I followed the Telerik example to perform client-side data binding using Page Methods/WebMethods and it's working great: Client Side Binding.
I'm trying to display a footer for the grid (not at the group level) with sums of the columns (to start I've only tried it with the first couple of numeric columns). The footer sums show up but the totals are always 0.
This is the page I've created:
The Code-Behind:
Thanks for your help,
James
I'm trying to display a footer for the grid (not at the group level) with sums of the columns (to start I've only tried it with the first couple of numeric columns). The footer sums show up but the totals are always 0.
This is the page I've created:
head runat="server">
<
title
></
title
>
<
script
type
=
"text/javascript"
src
=
"jquery-1.8.2.js"
></
script
>
<
script
type
=
"text/javascript"
>
$(document).ready(function () {
$('#lbtnGo').click(function () {
SaveGridValues();
});
});
</
script
>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function SaveGridValues() {
var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
var Updates = new Array();
for (var i = 0; i <= tableView._dataItems.length - 1; i++) {
var dataItem = tableView._dataItems[i];
var row = dataItem.get_element();
var label = row.children[0].children[0];
var Appx = label.innerText;
var checkBox = row.children[1].children[0];
var ZeroCostAppx = checkBox.checked;
var rtb0102InstHoursPer = tableView._dataItems[i].findControl("rtb0102InstHoursPer");
var current_rtb0102InstHoursPer = rtb0102InstHoursPer._value
var rtb0102InstAmountPer = tableView._dataItems[i].findControl("rtb0102InstAmountPer");
var current_rtb0102InstAmountPer = rtb0102InstAmountPer._value
var rtb0111TravelHoursPer = tableView._dataItems[i].findControl("rtb0111TravelHoursPer");
var current_rtb0111TravelHoursPer = rtb0111TravelHoursPer._value
var rtb0111TravelAmountPer = tableView._dataItems[i].findControl("rtb0111TravelAmountPer");
var current_rtb0111TravelAmountPer = rtb0111TravelAmountPer._value
var bd = new Object();
bd.appx = Appx;
bd.a01_02InstAmountPer = current_rtb0102InstAmountPer;
bd.a01_02InstHoursPer = current_rtb0102InstHoursPer;
bd.a01_11TravelAmountPer = current_rtb0111TravelAmountPer;
bd.a01_11TravelHoursPer = current_rtb0111TravelHoursPer;
bd.ZeroCostAppx = ZeroCostAppx;
Updates.push(bd);
}
PageMethods.UpdateBD("ACCS110155", Updates, GetData);
}
</
script
>
<
script
type
=
"text/javascript"
>
function pageLoad(sender, eventArgs) {
var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
GetData();
}
function GetData() {
PageMethods.GetData("ACCS110155", updateGrid);
}
function RadGrid1_Command(sender, args) {
//left blank
}
function updateGrid(result) {
var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
tableView.set_dataSource(result);
tableView.dataBind();
}
function RadGrid1_RowDataBound(sender, args) {
var chkZeroCost = args.get_item().findControl("chkZeroCostAppx");
if (chkZeroCost != null) {
chkZeroCost.checked = args.get_dataItem()["ZeroCostAppx"];
}
var radTextBox1 = args.get_item().findControl("rtb0102InstHoursPer"); // find control
radTextBox1.set_value(args.get_dataItem()["_01_02InstHoursPer"]);
var radTextBox2 = args.get_item().findControl("rtb0102InstAmountPer"); // find control
radTextBox2.set_value(args.get_dataItem()["_01_02InstAmountPer"]);
var rtb0111TravelHoursPer = args.get_item().findControl("rtb0111TravelHoursPer"); // find control
rtb0111TravelHoursPer.set_value(args.get_dataItem()["_01_11TravelHoursPer"]);
var rtb0111TravelAmountPer = args.get_item().findControl("rtb0111TravelAmountPer"); // find control
rtb0111TravelAmountPer.set_value(args.get_dataItem()["_01_11TravelAmountPer"]);
}
</
script
>
</
telerik:RadCodeBlock
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager1"
/>
<
div
>
<
telerik:RadGrid
ID
=
"RadGrid1"
EnableViewState
=
"false"
runat
=
"server"
AllowPaging
=
"false"
AllowSorting
=
"True"
AllowFilteringByColumn
=
"false"
GridLines
=
"None"
>
<
ItemStyle
Wrap
=
"false"
></
ItemStyle
>
<
MasterTableView
AllowMultiColumnSorting
=
"true"
TableLayout
=
"Fixed"
BackColor
=
"#f2f2f2"
ShowFooter
=
"true"
>
<
Columns
>
<
telerik:GridTemplateColumn
DataField
=
"Appx"
HeaderText
=
"Appx"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblAppx"
runat
=
"server"
></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"ZeroCostAppx"
HeaderText
=
"No cost"
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"chkZeroCostAppx"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"_01_02InstHoursPer"
HeaderText
=
"_01_02InstHoursPer"
Aggregate
=
"Sum"
DataType
=
"System.Decimal"
>
<
ItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"rtb0102InstHoursPer"
runat
=
"server"
Width
=
"70px"
BorderColor
=
"Transparent"
>
</
telerik:RadNumericTextBox
>
</
ItemTemplate
>
<
FooterTemplate
>
<
telerik:RadNumericTextBox
ID
=
"rtb0102InstHoursPerFOOTER"
runat
=
"server"
>
<
ClientEvents
OnLoad
=
"Load"
/>
</
telerik:RadNumericTextBox
>
</
FooterTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"_01_02InstAmountPer"
HeaderText
=
"_01_02InstAmountPer"
Aggregate
=
"Sum"
DataType
=
"System.Decimal"
UniqueName
=
"_01_02InstAmountPer"
>
<
ItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"rtb0102InstAmountPer"
runat
=
"server"
Width
=
"70px"
BorderColor
=
"Transparent"
Type
=
"Currency"
>
</
telerik:RadNumericTextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"_01_11TravelHoursPer"
HeaderText
=
"_01_11TravelHoursPer"
>
<
ItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"rtb0111TravelHoursPer"
runat
=
"server"
Width
=
"70px"
BorderColor
=
"Transparent"
>
</
telerik:RadNumericTextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"_01_11TravelAmountPer"
HeaderText
=
"_01_11TravelAmountPer"
>
<
ItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"rtb0111TravelAmountPer"
runat
=
"server"
Width
=
"70px"
BorderColor
=
"Transparent"
Type
=
"Currency"
>
</
telerik:RadNumericTextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnCommand
=
"RadGrid1_Command"
OnRowDataBound
=
"RadGrid1_RowDataBound"
>
</
ClientEvents
>
</
ClientSettings
>
</
telerik:RadGrid
>
</
div
>
<
div
>
<
asp:LinkButton
ID
=
"lbtnGo"
runat
=
"server"
Text
=
"Go"
OnClientClick
=
"return false;"
></
asp:LinkButton
>
</
div
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
>
</
telerik:RadAjaxLoadingPanel
>
</
form
>
</
body
>
The Code-Behind:
public
partial
class
_Default : System.Web.UI.Page
{
protected
override
void
OnInit(System.EventArgs e)
{
base
.OnInit(e);
RadScriptManager.GetCurrent(
this
).EnablePageMethods =
true
;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public
static
List<BudgetedDollar> GetData(
string
JobNumber)
{
DataClassesDataContext db =
new
DataClassesDataContext(ConfigurationManager.ConnectionStrings[
"JM_ConnStringUser"
].ToString());
var resultItems = (from BudgetedDollar dr
in
db.BudgetedDollars.Where(x => x.JobNumber.Equals(JobNumber)).AsEnumerable()
select dr).ToList<BudgetedDollar>();
return
resultItems;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public
static
void
UpdateBD(
string
JobNumber, Object o)
{
DataClassesDataContext db =
new
DataClassesDataContext(ConfigurationManager.ConnectionStrings[
"JM_ConnStringUser"
].ToString());
try
{
for
(
int
i = 0; i < ((
object
[])(o)).Length; i++)
{
db.sp_Update_BudgetedDollars(
JobNumber,
Int16.Parse(((System.Collections.Generic.Dictionary<
string
,
object
>)((
object
[])(o))[i])[
"appx"
].ToString()),
Boolean.Parse(((System.Collections.Generic.Dictionary<
string
,
object
>)((
object
[])(o))[i])[
"ZeroCostAppx"
].ToString()),
Decimal.Parse(((System.Collections.Generic.Dictionary<
string
,
object
>)((
object
[])(o))[i])[
"a01_02InstHoursPer"
].ToString()),
Decimal.Parse(((System.Collections.Generic.Dictionary<
string
,
object
>)((
object
[])(o))[i])[
"a01_02InstAmountPer"
].ToString()),
Decimal.Parse(((System.Collections.Generic.Dictionary<
string
,
object
>)((
object
[])(o))[i])[
"a01_11TravelHoursPer"
].ToString()),
Decimal.Parse(((System.Collections.Generic.Dictionary<
string
,
object
>)((
object
[])(o))[i])[
"a01_11TravelAmountPer"
].ToString()),
);
}
}
catch
(Exception ex)
{ }
}
}
Thanks for your help,
James