10 Answers, 1 is accepted

The following sample code will help you to achieve your requirement.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
GridLines
=
"None"
runat
=
"server"
OnCustomAggregate
=
"RadGrid1_CustomAggregate"
ShowFooter
=
"true"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"rooms"
HeaderText
=
"rooms"
UniqueName
=
"rooms"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"revenue"
HeaderText
=
"revenue"
UniqueName
=
"revenue"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"DailyRate"
HeaderText
=
"DailyRate"
UniqueName
=
"DailyRate"
Aggregate
=
"Custom"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_CustomAggregate(
object
sender, GridCustomAggregateEventArgs e)
{
if
(((Telerik.Web.UI.GridBoundColumn)e.Column).UniqueName ==
"DailyRate"
)
{
Double rooms = 0;
Double revenue = 0;
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
{
rooms += Convert.ToDouble(item[
"rooms"
].Text);
revenue += Convert.ToDouble(item[
"revenue"
].Text);
}
e.Result = revenue / rooms;
}
}
-Shinu.

Thanks for the quick the response. This code works great with the exception I changed the "Telerik.Web.UI.GridBoundColumn" to "Telerik.Web.UI.GridColumn" so that it works when there are more than one column type in the grid needing a custom footer.
Thanks again!
Tom


By using above code we cannot access the cell value if the item is in edit mode. In that case access the control in editform (TextBox) and then access the value and proceed with the above calculation. Sample code is given below.
C#:
protected
void
RadGrid1_CustomAggregate(
object
sender, GridCustomAggregateEventArgs e)
{
if
(((Telerik.Web.UI.GridBoundColumn)e.Column).UniqueName ==
"DailyRate"
)
{
Double rooms = 0;
Double revenue = 0;
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
{
if
(!item.IsInEditMode)
{
rooms += Convert.ToDouble(item[
"rooms"
].Text);
revenue += Convert.ToDouble(item[
"revenue"
].Text);
}
else
{
TextBox txtroom = (TextBox)item[
"rooms"
].Controls[0];
rooms += Convert.ToDouble(txtroom.Text);
TextBox txtrevenue = (TextBox)item[
"revenue"
].Controls[0];
revenue += Convert.ToDouble(txtrevenue.Text);
}
}
e.Result = revenue / rooms;
}
}
-Shinu.

I have one issue here. I bind the grid to sql view using sql datasource and auto paging. The grid also has filtering at column level.
When i use Aggregate = Sum it gives me correct total by adding all paged items. But when i change it to custom and write below code it gives me total of only that page. What should be done so that it gives correct total?
The reason i wan't it custom because i am building a report that will add check amount for unique check numbers only.
protected
void
PaymentsGrid_CustomAggregate(
object
sender, GridCustomAggregateEventArgs e)
{
if
(((Telerik.Web.UI.GridBoundColumn)e.Column).UniqueName ==
"CheckAmount"
)
{
Double checkAmount = 0;
foreach
(GridDataItem item
in
PaymentsGrid.MasterTableView.Items)
{
checkAmount += item[
"CheckAmount"
].Text.Replace(
"$"
,
""
).ToSafeDouble(0);
}
e.Result = checkAmount;
}
}
It depends how you calculate the custom total value in the code-behind event. The Items collection of the grid holds only the items on the current page. So if you build an aggregate by iterating over them it will be calculated only for the values shown on the current page. The grid does not construct items for records on the other pages for performance reasons. But in the CustomAggregate event you can access directly the whole datasource and execute a corresponding query which will be executed for all the records and not just the ones in the current page.
Kind regards,Marin
the Telerik team

If i check grid.mastertableview.datasource it is always null. How do i get the rows returned?
I am binding to sql view using sql datasource. Also the grid has filtering enabled. So users may filter the grid and i need to recalculate the value accordingly.
Regards
RadGrid does not persist a reference to the whole datasource for optimization purposes. That's why you cannot access directly the underlying data using the grid's API. Instead you can manually access the data by using for example the Select method of the SqlDataSource control which will return a DataView that can be enumerated.
I hope this helps.
Marin
the Telerik team

I am using RADGridView for WPF and my requirement is to have Aggregates on a column based on the aggregates of different columns..
For eg.
Qty Discount Net
100 10 90
200 20 180
300 30 270
Total 600 60 Aggregate(600-60)
How can i achieve this. I know i can total net column to display 540...but my requirement is different altogether...is there a feature which can let me do this ...we are using MVVM and dont want to put any code in code behind.
Thanks
This is a forum or ASP.NET AJAX Controls, you can get more accurate help if you post your questions in the relevant forum for WPF controls where it will be handled appropriately.
Kind regards,Marin
the Telerik team