Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
8160
WebDataGrid Custom Summary with Paging
posted

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;

    }

 

 

Parents
  • 8160
    posted

    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)
        {
            //calculate the St.dev summary
            if (e.Summary.CustomSummaryName == "STDEV")
            {
                //calculate the sum of all values
                double sum = 0.0;
     
                foreach (DataRecord dr in WebDataGrid1.GetDataView().DataAdapter.Records)
                {
                    // do whatever here
                    sum += Convert.ToDouble(dr.GetValue("UnitPrice"));
                }
                return sum;
            }
            return null;
        }

Reply Children
No Data