I have Footer row in my Radgrid with Text box as footer item template control for few columns. User can enter a value in text box and then click button to save it in database. I am not getting textbox value at runtime in button click event, its always ""
I am using the below code to read access footer value.
GridFooterItem footerItem = (GridFooterItem)gridBulkEdit.MasterTableView.GetItems(GridItemType.Footer)[0];
RadTextBox texte = (RadTextBox)footerItem.FindControl(
"txtPortfolioID"
);
please advise.
13 Answers, 1 is accepted
Your code looks correct, please make sure you haven't set its visibility to false. Here is a sample code that i tried which works fine. Please provide your full code if this doesn't help.
ASPX:
<
telerik:GridTemplateColumn
UniqueName
=
"GridTemplateColumn"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
"Label"
></
asp:Label
>
</
ItemTemplate
>
<
FooterTemplate
>
<
telerik:RadTextBox
ID
=
"RadTextBox1"
runat
=
"server"
>
</
telerik:RadTextBox
>
</
FooterTemplate
>
</
telerik:GridTemplateColumn
>
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
GridFooterItem footeritem = (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
RadTextBox txt = (RadTextBox)footeritem.FindControl(
"RadTextBox1"
);
//Access the RadTextBox
string
footertext = txt.Text;
//Get the Footer Text;
}
Thanks,
Princy
Thanks for your reply.
I have not set the visibility to false and I'm able to access the textbox object but the value is always empty. See my design code below.
<
telerik:GridTemplateColumn
UniqueName
=
"PortfolioID"
DataField
=
"DLS_PORTF"
HeaderText
=
"Portfolio ID"
>
<
ItemTemplate
>
<%#Eval("DLS_PORTF") %>
</
ItemTemplate
>
<
FooterTemplate
>
<
telerik:RadTextBox
ID
=
"txtPortfolioID"
runat
=
"server"
Wrap
=
"true"
>
<
ClientEvents
/>
</
telerik:RadTextBox
>
</
FooterTemplate
>
</
telerik:GridTemplateColumn
>
I was not able to replicate the issue, here is a sample code snippet , please try and see hows it different from your code.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
AllowPaging
=
"true"
ShowFooter
=
"true"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ID"
HeaderText
=
"ID"
UniqueName
=
"ID"
/>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Name"
UniqueName
=
"Name"
/>
<
telerik:GridTemplateColumn
UniqueName
=
"Number"
DataField
=
"Number"
HeaderText
=
"Number"
>
<
ItemTemplate
>
<%#Eval("Number")%>
</
ItemTemplate
>
<
FooterTemplate
>
<
telerik:RadTextBox
ID
=
"txtNumber"
runat
=
"server"
Wrap
=
"true"
>
</
telerik:RadTextBox
>
</
FooterTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Save"
OnClick
=
"Button1_Click"
/>
C#:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
dynamic data =
new
[] {
new
{ ID = 1, Name =
"Name1"
, Number=123},
new
{ ID = 2, Name =
"Name2"
, Number=234},
new
{ ID = 3, Name =
"Name3"
, Number=234},
new
{ ID = 4, Name =
"Name4"
, Number=456},
new
{ ID = 5, Name =
"Name5"
, Number=567},
new
{ ID = 6, Name =
"Name6"
, Number=567},
new
{ ID = 7, Name =
"Name7"
, Number=789},
new
{ ID = 8, Name =
"Name8"
, Number=896},
new
{ ID = 9, Name =
"Name9"
, Number=741}
};
RadGrid1.DataSource = data;
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
GridFooterItem footeritem = (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
RadTextBox txt = (RadTextBox)footeritem.FindControl(
"txtNumber"
);
string
footertext = txt.Text;
}
Thanks,
Princy
I have tried your code, but if I type any text and check the text box text value in button click, I get "". Did you manage to get the text box value at run time with your code?
Regards,
Giri
Yes i was able to get the value entered in the textbox using the previous code.
Thanks,
Princy
I'm using version 2013.3.1114.45
see the screenshot, it's weird :(
can u share the complete aspx and c# code?
You can download the full Sample code from the following link. Please run the sample solution and see if it is causing any issue at you end.
https://www.dropbox.com/s/area5m7e73y6i4b/FooterText.zip
Thanks,
Princy
any one know this answer plz riply
i am added dynamic textboxes but i m unable to find that values and id of that control under button click event
can any one know plzz plzz riply
aspx code
=================
<telerik:RadGrid ID="gvEmployees_Edit" AutoGenerateColumns="true" OnItemCreated="gvEmployees_Edit_ItemCreated" runat="server" CellSpacing="0" CellPadding="0" HeaderStyle-Font-Bold="true"
GridLines="None" OnItemDataBound="gvEmployees_Edit_ItemDataBound" >
<GroupingSettings CaseSensitive="false" />
<ClientSettings>
<Scrolling AllowScroll="true" UseStaticHeaders="true" FrozenColumnsCount="2" ScrollHeight="450px"/>
</ClientSettings>
<MasterTableView AllowFilteringByColumn="false" FilterItemStyle-BackColor="#DCEDFD" DataKeyNames="UserID" >
<Columns>
<%--<telerik:GridBoundColumn DataField="UserID" Visible="False" UniqueName="UserID" HeaderText="UserID">
</telerik:GridBoundColumn>--%>
</Columns>
<NoRecordsTemplate>
<%= Resources.Controls.Grid_EmptyRow %>
</NoRecordsTemplate>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
</telerik:RadGrid>
==========================================================
cs code
------------------
protected void gvEmployees_Edit_ItemDataBound(object sender, GridItemEventArgs e)
{
int I = 0;
if (e.Item.ItemType != null)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (column.UniqueName != "EmpID" && column.UniqueName != "Name" && column.UniqueName != "UserID")
{
I++;
TextBox tbEditBox = new TextBox();
tbEditBox.Text = item[column].Text.Replace(" ", "");
tbEditBox.Width = Unit.Pixel(40);
tbEditBox.ID = "txt" + I;
tbEditBox.MaxLength = 3;
tbEditBox.Text.ToUpper();
tbEditBox.EnableViewState = false;
item[column].Controls.Clear();
item[column].Controls.Add(tbEditBox);
}
}
}
}
}
===========================
Click Event
----------------
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (GridDataItem row in gvEmployees_Edit.MasterTableView.Items)
{
Textbox txt=item.findcontrol("txt") as textbox;
}
}
When using .FindControl(), you must pass to it the same string that is passed to the ID property of the control when creating it. Perhaps you should consider generating the ID of the textbox by using the UniqueName of its column, so it is predictable and you can generate it again when accessing the textbox.
It is also important to note that you should create controls either in the markup, or with every postback (meaning, in Page_Init, or in the ItemCreated event).
Regards,
Marin Bratanov
Progress Telerik
Hi,
I have two radgrids 1 and 2. Ragdrid1 has footer sum aggregate of column 'SID' and Radgrid2 has footer sum aggregate of 'LOADS'. I want to compare both footer values. Please suggest.
Thank you.
I got it.
If TypeOf e.Item Is GridFooterItem Then
Dim footer1 As GridFooterItem = CType(RadGrid1.MasterTableView.GetItems(GridItemType.Footer)(0), GridFooterItem)
Dim gstrSidTotal As String = footer1("QTY_EXP").Text
Dim footer2 As GridFooterItem = CType(RadGrid2.MasterTableView.GetItems(GridItemType.Footer)(0), GridFooterItem)
Dim gstrLoadTotal As String = footer2("TOTAL_QTY").Text
end If
But now, is there a way to get only values. Here, the values i get are like 'SUM: 1200' or 'SUM: 800' or so on. Is there a way I could access only the values after ':'?
You can parse out the text from the cell contents. Since you know what the original aggregate is, you know the format that is set for the footer so you can string.Replace() it.
Alternatively, implement your own custom aggregation and you will be able to store actual results in an object in the page class. Here's how to implement your own aggregate functions: https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-create-custom-aggregate-functions.
Regards,
Marin Bratanov
Progress Telerik