Ask a Question related to ASP.NET General, Design and Development.
-
SamIAm #1
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>
SamIAm Guest
-
How Access Controls In A DataGrid Footer
OK - I am prepared for everyone who will tell me this is a hack and bad idea; however, this is the only way I could find to solve this problem, and... -
Using labels in the HeaderTemplate of a datagrid or datalist
when I try to access this label to place a text in it in the code. I get this error - Object reference not set to an instance of an object. I... -
DataGrid HeaderTemplate Bug?
I use theDataGrid control and specify a HeaderTemplate for the grid. I the rendered HTML the header row is not rendered as <th> elements. Is this a... -
How to access the controls that are inside of a DataList/DataGrid using JS?
My problem is simple, i have a datalist control with some controls inside of EditTemplate (the problem is the same in the DataGrid). I want to have... -
Method to Access Controls In A DataGrid Footer
Hi, I noticed some ppls are struggling on access Controls In A DataGrid Footer this is the way i done and works pretty well . Take a look... -
Bipin Joshi [MVP] #2
Re: How do you access controls in the HeaderTemplate of a DataGrid
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 - [url]www.dotnetbips.com[/url]
Coding, Consulting & Training - [url]www.bipinjoshi.com[/url]
Microsoft MVP
"SamIAm" <samiam@rubbachicken.com> wrote in message
news:ecuKpG7ODHA.452@TK2MSFTNGP11.phx.gbl...and> Hi
>
> I have a DataGrid called dgTraders 1 of the columns is a template column> 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>
>
>
Bipin Joshi [MVP] Guest



Reply With Quote

