How do you access controls in the HeaderTemplate of a DataGrid

Discussion in 'ASP .Net' started by SamIAm, Jun 26, 2003.

  1. SamIAm

    SamIAm Guest

    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, Jun 26, 2003
    #1
    1. Advertising

  2. 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>
    > <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], Jun 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vijaya
    Replies:
    2
    Views:
    2,634
    Vijaya
    Nov 13, 2003
  2. Cheng
    Replies:
    2
    Views:
    9,318
    dany7487
    Nov 14, 2007
  3. Yan Wang

    Controls in HeaderTemplate

    Yan Wang, Apr 20, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    554
    Yan Wang
    Apr 21, 2004
  4. Mick
    Replies:
    2
    Views:
    2,075
  5. Ryan Taylor
    Replies:
    1
    Views:
    190
    Ryan Taylor
    Jan 13, 2005
Loading...

Share This Page