How do you access controls in the HeaderTemplate of a DataGrid

S

SamIAm

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>
 
B

Bipin Joshi [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top