This is a migrated thread and some comments may be shown as answers.
Custom Aggregate in child table
4 Answers 41 Views
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 2
Jose asked on 24 Nov 2010, 08:00 PM
Hi,

I need to calculate a custom aggregate value in a GridTableView based on the value of other 2 aggregate values (Sum).
GridTableView rise the OnCustomAggregate event for this column but I don't know how to get the aggregate values of other columns.

I need to calculate a value like this: (1 - (TotalCost / TotalPrice)) in the custom aggregate column.
TotalCost and TotalPrice are Sum aggregate values of other columns.

Any idea?
Regards
Jose

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 25 Nov 2010, 06:43 AM
Hello Jose,

The following code snippet shows how to access the footer value for other columns in OnCustomAggregare event.

C#:
protected void RadGrid1_CustomAggregate(object sender, GridCustomAggregateEventArgs e)
   {
       GridFooterItem footerItem = (GridFooterItem)e.Item;
       string footer=footerItem["TotalCost"].Text // accessing footer value using ColumnUniueName
   }

Thanks,
Princy.
0
Jose
Top achievements
Rank 2
answered on 25 Nov 2010, 08:20 PM
Hi Princy,

Thank you very much for your help.
It's works very nice.
Regards
Jose
0
Jose
Top achievements
Rank 2
answered on 25 Nov 2010, 08:36 PM
(Edited...: solved with a simple if --> if (e.Item is GridFooterItem))


Hi Princy,

I'm having a side effect with the custom aggregate.

When I group the child grid I'm receiving the next error:
Unable to cast object of type 'Telerik.Web.UI.GridGroupFooterItem' to type 'Telerik.Web.UI.GridFooterItem'.

This is the code:

protected void ListGrid_CustomAggregate(object sender, GridCustomAggregateEventArgs e)
       {
           GridFooterItem footerItem = (GridFooterItem)e.Item;
 
           decimal totalCost = Decimal.Parse(footerItem["TotalCost"].Text, NumberStyles.Any);
           decimal totalPrice = Decimal.Parse(footerItem["TotalPrice"].Text, NumberStyles.Any);
 
           if (totalPrice > 0)
               e.Result = 1 - (totalCost / totalPrice);
           else
               e.Result = 0;
       }
0
Princy
Top achievements
Rank 1
answered on 26 Nov 2010, 06:28 AM
Hello Jose,

Since you have enabled Grouping, make the following changes in the above code to eliminate the error
.
C#:
protected void RadGrid1_CustomAggregate(object sender, GridCustomAggregateEventArgs e)
   {
      if (e.Item is GridGroupFooterItem)
       {
           GridGroupFooterItem footerItem = (GridGroupFooterItem)e.Item;
           string id = footerItem["TotalCost"].Text;
       }
   }

Thanks,
Princy.
Tags
Grid
Asked by
Jose
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Jose
Top achievements
Rank 2
Share this question
or