Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do you access controls in the HeaderTemplate of a DataGrid

Reply
Thread Tools

How do you access controls in the HeaderTemplate of a DataGrid

 
 
SamIAm
Guest
Posts: n/a
 
      06-26-2003
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>
<aspropDownList id="selCities"
runat="server"></aspropDownList>
</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>


 
Reply With Quote
 
 
 
 
Bipin Joshi [MVP]
Guest
Posts: n/a
 
      06-26-2003
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" <> wrote in message
news:...
> 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>
> <aspropDownList id="selCities"
> runat="server"></aspropDownList>
> </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>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find control in headertemplate of datagrid Cheng ASP .Net 2 11-14-2007 03:57 PM
Access Repeater's HeaderTemplate Child Controls Mick ASP .Net 2 01-14-2005 01:47 PM
Wiring up an ImageButton event in a repeater controls headertemplate tag Ryan Taylor ASP .Net Web Controls 1 01-13-2005 09:26 PM
Controls in HeaderTemplate Yan Wang ASP .Net 6 04-21-2004 01:35 PM
Can we bind data to textbox in a headertemplate of a datagrid Vijaya ASP .Net 2 11-13-2003 06:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57