Access the FooterTemplates TextBox control on the Button Click Event

A

Arulraja

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
 
T

Teemu Keiski

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).
 
A

Arulraja

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 said:
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 said:
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
 
T

Teemu Keiski

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 said:
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" <[email protected]> wrote in message
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top