Skip to main content
A newer version of this page is available. .

How to: Calculate Custom Total Summaries

This example shows how to implement a custom summary calculation.

Create a summary item within the ASPxGridView.TotalSummary collection, and customize its settings, as shown below:

exCustomSummaryEditor

The ASPxGridBase.CustomSummaryCalculate event is handled to sum the budgets of selected departments.

Note that in order to process selection changes on the server side, you can either set the ASPxGridBehaviorSettings.ProcessSelectionChangedOnServer property to true or handle the ASPxClientGridView.SelectionChanged client event, and call the ASPxClientGridView.PerformCallback client method.

Note

The ASPxGridView.EnableRowsCache property should be set to false.

The image below shows the result:

exCustomSummaryResult

int totalSum;
protected void ASPxGridView1_CustomSummaryCalculate(object sender,
    DevExpress.Data.CustomSummaryEventArgs e) {
    // Initialization.
    if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Start)
        totalSum = 0;
    else    
    // Calculation.
    if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Calculate){
        if(ASPxGridView1.Selection.IsRowSelectedByKey(e.GetValue(ASPxGridView1.KeyFieldName)))
            totalSum += Convert.ToInt32(e.FieldValue);}
    else
    // Finalization.
    if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize)
        e.TotalValue = totalSum;
}