Professional Web Applications Themes

Access the FooterTemplates TextBox control on the Button Click Event - ASP.NET Data Grid Control

Hello, I have the following code in the .aspx file <asp:TemplateColumn HeaderText="&#160;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_n ame")%>' 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 ...

  1. #1

    Default Access the FooterTemplates TextBox control on the Button Click Event

    Hello,

    I have the following code in the .aspx file

    <asp:TemplateColumn HeaderText="&#160;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_n ame")%>'
    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 Guest

  2. #2

    Default Re: Access the FooterTemplates TextBox control on the Button Click Event

    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" <arulrajalivihotmail.com> wrote in message
    news:d2b752f5.0311121320.1fcfc9a2posting.google.c om...
    > Hello,
    >
    > I have the following code in the .aspx file
    >
    > <asp:TemplateColumn HeaderText="&#160;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_n ame")%>'
    > 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 Guest

  3. #3

    Default Re: Access the FooterTemplates TextBox control on the Button Click Event

    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" <jotekeaspalliance.com> wrote in message news:<#OGf9GbqDHA.1928TK2MSFTNGP12.phx.gbl>...
    > 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" <arulrajalivihotmail.com> wrote in message
    > news:d2b752f5.0311121320.1fcfc9a2posting.google.c om...
    > > Hello,
    > >
    > > I have the following code in the .aspx file
    > >
    > > <asp:TemplateColumn HeaderText="&#160;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_n ame")%>'
    > > 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 Guest

  4. #4

    Default Re: Access the FooterTemplates TextBox control on the Button Click Event

    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" <arulrajalivihotmail.com> wrote in message
    news:d2b752f5.0311130655.55c1f433posting.google.c om...
    > 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" <jotekeaspalliance.com> wrote in message
    news:<#OGf9GbqDHA.1928TK2MSFTNGP12.phx.gbl>...
    > > 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" <arulrajalivihotmail.com> wrote in message
    > > news:d2b752f5.0311121320.1fcfc9a2posting.google.c om...
    > > > Hello,
    > > >
    > > > I have the following code in the .aspx file
    > > >
    > > > <asp:TemplateColumn HeaderText="&#160;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_n ame")%>'
    > > > 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 Guest

Similar Threads

  1. The button(in repeater)'s click event
    By balrog1983 in forum Macromedia Flex General Discussion
    Replies: 8
    Last Post: June 18th, 07:53 PM
  2. Button Click Event Not Working
    By JeffHung in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: May 11th, 09:11 AM
  3. UserControl not capturing Button click event when loaded with PlaceHolder Control
    By Ralph Krausse in forum ASP.NET Building Controls
    Replies: 1
    Last Post: September 15th, 09:15 PM
  4. Replies: 2
    Last Post: May 28th, 06:23 AM
  5. Replies: 3
    Last Post: July 18th, 05:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139