How to: Calculate Custom Total Summaries

This example shows how to implement a custom summary calculation.

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 ASPxClientCardView.SelectionChanged client event and call the clientASPxClientCardView.PerformCallback method.

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