473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do you access controls in the HeaderTemplate of a DataGrid

Hi

I have a DataGrid called dgTraders 1 of the columns is a template column and
this column has a Dropdown box in its HeaderTemplate section. The Dropdown
box is called selCities. How do I access this DropDown box at runtime?

<asp:datagrid id="dgTraders" runat="server" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4"
GridLines="Vertical" ForeColor="Black" AutoGenerateColumns="False"
Width="100%">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#CE5D5A"></SelectedItemStyle>
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<ItemStyle BackColor="#F7F7DE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#6B696B"></HeaderStyle>
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="Firstname"
HeaderText="Firstname"></asp:BoundColumn>
<asp:BoundColumn DataField="Lastname"
HeaderText="Lastname"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="City">
<HeaderTemplate>
<asp:DropDownList id="selCities"
runat="server"></asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.City") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.City") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="CountryName"
HeaderText="Country"></asp:BoundColumn>
<asp:BoundColumn DataField="SubscriptionStatusName"
HeaderText="Subscription"></asp:BoundColumn>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
Nov 17 '05 #1
1 5228
you can use ItemCreate and ItemDataBound events, find the type of item -
item, header, alternating item etc. - and then use FindControl on that item
i.e. DataGrid row.

--
Regards,
Bipin Joshi
Webmaster - www.dotnetbips.com
Coding, Consulting & Training - www.bipinjoshi.com
Microsoft MVP

"SamIAm" <sa****@rubbachicken.com> wrote in message
news:ec*************@TK2MSFTNGP11.phx.gbl...
Hi

I have a DataGrid called dgTraders 1 of the columns is a template column and this column has a Dropdown box in its HeaderTemplate section. The Dropdown
box is called selCities. How do I access this DropDown box at runtime?

<asp:datagrid id="dgTraders" runat="server" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4"
GridLines="Vertical" ForeColor="Black" AutoGenerateColumns="False"
Width="100%">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#CE5D5A"></SelectedItemStyle>
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<ItemStyle BackColor="#F7F7DE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#6B696B"></HeaderStyle>
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="Firstname"
HeaderText="Firstname"></asp:BoundColumn>
<asp:BoundColumn DataField="Lastname"
HeaderText="Lastname"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="City">
<HeaderTemplate>
<asp:DropDownList id="selCities"
runat="server"></asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.City") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.City") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="CountryName"
HeaderText="Country"></asp:BoundColumn>
<asp:BoundColumn DataField="SubscriptionStatusName"
HeaderText="Subscription"></asp:BoundColumn>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
2
by: | last post by:
Hello All, I am having a lot of difficulty trying to bind a templated column, that is programmatically created for a datagrid, to a datasource column. I have a datasource containing 2 columns,...
1
by: bill yeager | last post by:
I did some more debugging and found the following: 1) I placed the following code in the button event just to see if I could cycle thru the datagrid control collection: <code> Dim strhello As...
5
by: Yan Wang | last post by:
Hi! Does anyone know how to get the text in textbox field which is in HeaderTemplate of a DataGrid? In the following code, I can not get text of "tbName". I typed something in that box. I can...
2
by: 2obvious | last post by:
Below is a cut-and-paste code example that runs. It demonstrates some results which confuse me. It uses a DataGrid to make a table with 12 rows, each containing a TextBox and a CustomValidator....
1
by: Raed Sawalha | last post by:
i have aspx page with user control containing a datagrid , the datagrid has TempleteColumn with checkbox in header and item ( doing multiselect task) I wondering how Can get the checkboxes status...
0
by: upendra | last post by:
Hi, I am B.V.Ramesh Babu.I am working as software programmer using .net.We are using asp.net1.1 with C#.net as coding.I hope that i will get the required support from you. Here is my requirement....
1
by: anjali.lourda | last post by:
Hi, We are trying to use the accordion control from ajaxcontroltoolkit by databinding to an sqldatasource. The accordion binds to the datasource perfectly. However, We are not able to access the...
1
by: RN1 | last post by:
Consider the following DataGrid: -------------------------------------------------------------------------------- <asp:DataGrid ID="dgMarks" AutoGenerateColumns="false" runat="server"> <Columns>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.