Access the FooterTemplates TextBox control on the Button Click Event

Discussion in 'ASP .Net Datagrid Control' started by Arulraja, Nov 12, 2003.

  1. Arulraja

    Arulraja Guest

    Hello,

    I have the following code in the .aspx file

    <asp:TemplateColumn HeaderText=" FG Name">
    <HeaderStyle ForeColor="White"></HeaderStyle>
    <ItemStyle HorizontalAlign="Center" Width="200px"></ItemStyle>
    <ItemTemplate>
    <asp:TextBox id=txt_fg Width="200px" Runat="server" Text='<%#
    DataBinder.Eval(Container,"DataItem.family_group_name")%>'
    MaxLength="100" />
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox id="footerfg" Width="200px" runat="server" />
    </FooterTemplate>
    </asp:TemplateColumn>


    In the code behind button click event i have the follwing code

    foreach (DataGridItem item in grid_1.Items)
    {
    // get values from UI
    TextBox txtf = (TextBox)item.Cells[1].FindControl("txt_fg");
    }


    But this one is giving me only the DataGridItems(Items and
    ALternativeItems) not the Footer Items. If I pass the Footer TextBox
    ID to the FindControl method it return's a null.

    If I try the same code in the ItemCreated Event the TextBox "TEXT"
    property return's empty string.

    Can somebody help me to fix this problem? or Direct me how to access
    the Footer TextBox value on the Button Click event.

    Thx
    Arul
     
    Arulraja, Nov 12, 2003
    #1
    1. Advertising

  2. Arulraja

    Teemu Keiski Guest

    Hi,

    //Header
    DataGridItem header=(DataGridItem)dg.Controls[0].Controls[0];

    //Footer
    DataGridItem footer=
    (DataGridItem)dg.Controls[0].Controls[Controls[0].Controls.Count - 1];

    you can then search up controls from these. REason for this structure is
    that header & footer are actually controls in DataGridTable instance which
    is a child control of DataGrid (DataGridTable is actually the grid itself as
    Table and some of the layout functionality we see in DataGrid comes from
    this table).

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Arulraja" <> wrote in message
    news:...
    > Hello,
    >
    > I have the following code in the .aspx file
    >
    > <asp:TemplateColumn HeaderText=" FG Name">
    > <HeaderStyle ForeColor="White"></HeaderStyle>
    > <ItemStyle HorizontalAlign="Center" Width="200px"></ItemStyle>
    > <ItemTemplate>
    > <asp:TextBox id=txt_fg Width="200px" Runat="server" Text='<%#
    > DataBinder.Eval(Container,"DataItem.family_group_name")%>'
    > MaxLength="100" />
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:TextBox id="footerfg" Width="200px" runat="server" />
    > </FooterTemplate>
    > </asp:TemplateColumn>
    >
    >
    > In the code behind button click event i have the follwing code
    >
    > foreach (DataGridItem item in grid_1.Items)
    > {
    > // get values from UI
    > TextBox txtf = (TextBox)item.Cells[1].FindControl("txt_fg");
    > }
    >
    >
    > But this one is giving me only the DataGridItems(Items and
    > ALternativeItems) not the Footer Items. If I pass the Footer TextBox
    > ID to the FindControl method it return's a null.
    >
    > If I try the same code in the ItemCreated Event the TextBox "TEXT"
    > property return's empty string.
    >
    > Can somebody help me to fix this problem? or Direct me how to access
    > the Footer TextBox value on the Button Click event.
    >
    > Thx
    > Arul
     
    Teemu Keiski, Nov 13, 2003
    #2
    1. Advertising

  3. Arulraja

    Arulraja Guest

    Thanks a lot Teemu Keiski,

    I couldn't findout this information anywhere in the Net. Hopefully
    other's also will get it from your answer.

    Thanks
    Arul


    "Teemu Keiski" <> wrote in message news:<#>...
    > Hi,
    >
    > //Header
    > DataGridItem header=(DataGridItem)dg.Controls[0].Controls[0];
    >
    > //Footer
    > DataGridItem footer=
    > (DataGridItem)dg.Controls[0].Controls[Controls[0].Controls.Count - 1];
    >
    > you can then search up controls from these. REason for this structure is
    > that header & footer are actually controls in DataGridTable instance which
    > is a child control of DataGrid (DataGridTable is actually the grid itself as
    > Table and some of the layout functionality we see in DataGrid comes from
    > this table).
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    >
    > "Arulraja" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have the following code in the .aspx file
    > >
    > > <asp:TemplateColumn HeaderText=" FG Name">
    > > <HeaderStyle ForeColor="White"></HeaderStyle>
    > > <ItemStyle HorizontalAlign="Center" Width="200px"></ItemStyle>
    > > <ItemTemplate>
    > > <asp:TextBox id=txt_fg Width="200px" Runat="server" Text='<%#
    > > DataBinder.Eval(Container,"DataItem.family_group_name")%>'
    > > MaxLength="100" />
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:TextBox id="footerfg" Width="200px" runat="server" />
    > > </FooterTemplate>
    > > </asp:TemplateColumn>
    > >
    > >
    > > In the code behind button click event i have the follwing code
    > >
    > > foreach (DataGridItem item in grid_1.Items)
    > > {
    > > // get values from UI
    > > TextBox txtf = (TextBox)item.Cells[1].FindControl("txt_fg");
    > > }
    > >
    > >
    > > But this one is giving me only the DataGridItems(Items and
    > > ALternativeItems) not the Footer Items. If I pass the Footer TextBox
    > > ID to the FindControl method it return's a null.
    > >
    > > If I try the same code in the ItemCreated Event the TextBox "TEXT"
    > > property return's empty string.
    > >
    > > Can somebody help me to fix this problem? or Direct me how to access
    > > the Footer TextBox value on the Button Click event.
    > >
    > > Thx
    > > Arul
     
    Arulraja, Nov 13, 2003
    #3
  4. Arulraja

    Teemu Keiski Guest

    You could access then easier when you are on say ItemCreated event when the
    event is raised for every item. In your case you were accessing them by
    looping through the Items collection so it needed bit another approach.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "Arulraja" <> wrote in message
    news:...
    > Thanks a lot Teemu Keiski,
    >
    > I couldn't findout this information anywhere in the Net. Hopefully
    > other's also will get it from your answer.
    >
    > Thanks
    > Arul
    >
    >
    > "Teemu Keiski" <> wrote in message

    news:<#>...
    > > Hi,
    > >
    > > //Header
    > > DataGridItem header=(DataGridItem)dg.Controls[0].Controls[0];
    > >
    > > //Footer
    > > DataGridItem footer=
    > > (DataGridItem)dg.Controls[0].Controls[Controls[0].Controls.Count - 1];
    > >
    > > you can then search up controls from these. REason for this structure is
    > > that header & footer are actually controls in DataGridTable instance

    which
    > > is a child control of DataGrid (DataGridTable is actually the grid

    itself as
    > > Table and some of the layout functionality we see in DataGrid comes from
    > > this table).
    > >
    > > --
    > > Teemu Keiski
    > > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > > ASP.NET Forum Moderator, AspAlliance Columnist
    > >
    > > "Arulraja" <> wrote in message
    > > news:...
    > > > Hello,
    > > >
    > > > I have the following code in the .aspx file
    > > >
    > > > <asp:TemplateColumn HeaderText=" FG Name">
    > > > <HeaderStyle ForeColor="White"></HeaderStyle>
    > > > <ItemStyle HorizontalAlign="Center" Width="200px"></ItemStyle>
    > > > <ItemTemplate>
    > > > <asp:TextBox id=txt_fg Width="200px" Runat="server" Text='<%#
    > > > DataBinder.Eval(Container,"DataItem.family_group_name")%>'
    > > > MaxLength="100" />
    > > > </ItemTemplate>
    > > > <FooterTemplate>
    > > > <asp:TextBox id="footerfg" Width="200px" runat="server" />
    > > > </FooterTemplate>
    > > > </asp:TemplateColumn>
    > > >
    > > >
    > > > In the code behind button click event i have the follwing code
    > > >
    > > > foreach (DataGridItem item in grid_1.Items)
    > > > {
    > > > // get values from UI
    > > > TextBox txtf = (TextBox)item.Cells[1].FindControl("txt_fg");
    > > > }
    > > >
    > > >
    > > > But this one is giving me only the DataGridItems(Items and
    > > > ALternativeItems) not the Footer Items. If I pass the Footer TextBox
    > > > ID to the FindControl method it return's a null.
    > > >
    > > > If I try the same code in the ItemCreated Event the TextBox "TEXT"
    > > > property return's empty string.
    > > >
    > > > Can somebody help me to fix this problem? or Direct me how to access
    > > > the Footer TextBox value on the Button Click event.
    > > >
    > > > Thx
    > > > Arul
     
    Teemu Keiski, Nov 14, 2003
    #4
    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.

Share This Page