6 Answers, 1 is accepted
Please check the below link. In this link you can able to find server and client side code.
Accessing and validating controls client-side inside a hierarchical RadGrid
Thanks,
Jayesh Goyani
Please take a look at the following code snippet.
ASPX:
<
telerik:GridTemplateColumn
HeaderText
=
"Number"
>
<
ItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"ValueTxt"
runat
=
"server"
AutoPostBack
=
"true"
Value
=
"0"
OnTextChanged
=
"ValueTxt_TextChanged"
>
</
telerik:RadNumericTextBox
>
</
ItemTemplate
>
<
FooterTemplate
>
<
telerik:RadNumericTextBox
ID
=
"TotalTxtBox"
runat
=
"server"
>
</
telerik:RadNumericTextBox
>
</
FooterTemplate
>
</
telerik:GridTemplateColumn
>
From ServerSide:
C#:
int
total;
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item=(GridDataItem)e.Item;
RadNumericTextBox txt=(RadNumericTextBox)item.FindControl(
"ValueTxt"
);
int
fieldValue =
int
.Parse(txt.Text);
total += fieldValue;
}
if
(e.Item
is
GridFooterItem)
{
GridFooterItem footerItem = e.Item
as
GridFooterItem;
RadNumericTextBox footertxt = (RadNumericTextBox)footerItem.FindControl(
"TotalTxtBox"
);
footertxt.Text = total.ToString();
}
}
protected
void
ValueTxt_TextChanged(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
{
RadNumericTextBox txt = (RadNumericTextBox)item.FindControl(
"ValueTxt"
);
int
fieldValue =
int
.Parse(txt.Text);
total += fieldValue;
}
foreach
(GridFooterItem footerItem
in
RadGrid1.MasterTableView.GetItems(GridItemType.Footer))
{
RadNumericTextBox footertxt = (RadNumericTextBox)footerItem.FindControl(
"TotalTxtBox"
);
footertxt.Text = total.ToString();
}
}
For doing it from client you can use the ClientEvents-OnValueChanged="OnValueChanged" event for the ItemTemplate RadNumericTextBox 'ValueTxt'.
From ClientSide:
JS:
<script type=
"text/javascript"
>
function
OnValueChanged(sender, args) {
var
grid = $find(
"<%=RadGrid1.ClientID %>"
);
var
totalAmount = 0;
if
(grid) {
var
MasterTable = grid.get_masterTableView();
var
Rows = MasterTable.get_dataItems();
for
(
var
i = 0; i < Rows.length; i++) {
var
row = Rows[i];
var
txtQuntity1 = row.findControl(
"ValueTxt"
);
totalAmount = totalAmount + txtQuntity1.get_value();
}
}
var
footerTextBox =
'<%= ((GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0]).FindControl("TotalTxtBox").ClientID %>'
;
var
TextBox = document.getElementById(footerLabelID);
TextBox.control.set_value(totalAmount);
}
</script>
Thanks,
Princy
Hello,
Where are you getting footerLabelID from? I was trying to implement this into my project.
Ramey
You can check the following articles:
http://www.telerik.com/help/aspnet-ajax/grid-totals-with-numerictextbox.html
http://www.telerik.com/help/aspnet-ajax/grid-totals-in-footers.html
http://www.telerik.com/help/aspnet-ajax/grid-using-getitems-getcolumn-methods.html​
These posts, too:
http://www.telerik.com/forums/radgrid-group-footer-dynamic-calculation
http://www.telerik.com/forums/how-to-change-keypress-event-in-telerik-grid
http://www.telerik.com/forums/how-to-changes-telerik-grid-running-total-footer-template​
I am also attaching another web site sample for reference.
I hope these resources will prove helpful.
Regards,
Eyup
Telerik
Hi Eyup,
Thank you for you quick response. Currently my grid is using batch edit mode and I've implemented Telerik's batchmanagerextentions.js to handle multiple radcomboboxes using tooltips. I have one GridBoundColumn and I need to calculate the sum for all of those values client side so it will be a live updated value. I haven't figured out how to use aggregates since the datatype is a varchar. If I use a template column once I click on a cell for it to enter into batch edit mode the values aren't saved after entered. So this is basically where I am at currently. I wanted to see if there was a way to add up all work percents in my column and total it in the footer but if one changes then change the footer total accordingly. I haven't been able to find any solutions thus far. If you know of any way it would be very helpful.
Thanks,
Ramey
I suggest that you continue your conversation on the following forum thread and leverage the approach suggested by my colleague:
http://marketplace.telerik.com/forums/footer-total-in-batch-edit-mode
Regards,
Eyup
Telerik