When Paging is enabled custom summaries are calculated for the current page.
protected object WebDataGrid1_CalculateCustomSummary(object sender, CustomSummaryEventArgs e) { //calculate the St.dev summary if (e.Summary.CustomSummaryName == "STDEV") { //calculate the sum of all values double sum = 0.0; int n = 0; foreach (GridRecord gr in this.WebDataGrid1.Rows) { sum += Convert.ToDouble(gr.Items[1].Value); ++n; } //calculate the sum of squared deviations double mean = sum / n; sum = 0; foreach (GridRecord gr in this.WebDataGrid1.Rows) { sum += Math.Pow(mean - Convert.ToDouble(gr.Items[1].Value), 2); } sum = sum / (n - 1); return Math.Round(Math.Sqrt(sum), 2); } return null; }
{
//calculate the St.dev summary
if (e.Summary.CustomSummaryName == "STDEV")
//calculate the sum of all values
double sum = 0.0;
int n = 0;
foreach (GridRecord gr in this.WebDataGrid1.Rows)
sum += Convert.ToDouble(gr.Items[1].Value);
++n;
}
//calculate the sum of squared deviations
double mean = sum / n;
sum = 0;
sum += Math.Pow(mean - Convert.ToDouble(gr.Items[1].Value), 2);
sum = sum / (n - 1);
return Math.Round(Math.Sqrt(sum), 2);
return null;
To calculate custom summary for all pages we could loop through DataView() record collection:
protected object WebDataGrid1_CalculateCustomSummary(object sender, Infragistics.Web.UI.GridControls.CustomSummaryEventArgs e)
foreach (DataRecord dr in WebDataGrid1.GetDataView().DataAdapter.Records)
// do whatever here
sum += Convert.ToDouble(dr.GetValue("UnitPrice"));
return sum;
Hi Hristo,
Your sample doesn't work as intended for me.
Actually it works on the 1st page of data only. If I'm on any other page the DataAdapter.Records returned have their startindex changed to the new page.
This behaves in a way that when we are in the last page of data the summary only displays the total for the last page.
I tried setting the startindex to something else, but as this is the same adapter as the grid is using I experienced unintended results.
Are you able to reproduce what I am experiencing? How would you suggest it be corrected?
I'm using 2048 NetAdvantage ASP.NET
Thanks,
-Victor