Skip to main content
Tab

ASPxGridBase.CustomSummaryCalculate Event

Enables you to calculate summary values manually.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

#Declaration

public event CustomSummaryEventHandler CustomSummaryCalculate

#Event Data

The CustomSummaryCalculate event's data class is CustomSummaryEventArgs. The following properties provide information specific to this event:

Property Description
FieldValue Gets the processed field value.
GroupLevel Gets the nested level of the group whose summary value is being calculated.
GroupRowHandle Gets a value identifying the group row whose child data rows are involved in summary calculation.
IsGroupSummary Gets whether a group summary value is being calculated.
IsTotalSummary Gets whether a total summary value is being calculated.
Item Gets a summary item whose value is being calculated.
Mode Specifies how summaries are calculated - against all rows or for the selected rows.
Row Gets the currently processed row.
RowHandle Gets the handle of the processed row.
SummaryProcess Gets a value indicating calculation stage.
TotalValue Gets or sets the total summary value.
TotalValueReady Gets or sets whether the Calculation stage of the custom summary calculation process should be skipped.

The event data class exposes the following methods:

Method Description
GetGroupSummary(Int32, Object) Returns the value of the specified group summary for the specified group row.
GetValue(String) Returns the value in the specified field

#Remarks

Total summaries and group summaries provide five predefined aggregate functions. These functions allow you to calculate the number of rows, the maximum and minimum values, the sum and the average value. If you need to calculate a summary value using an aggregate function not included in the predefined set, set the summary item’s ASPxSummaryItemBase.SummaryType property to Custom and handle the CustomSummaryCalculate event.

The CustomSummaryCalculate event fires for each row involved in summary calculation. When calculating a total summary value, the event is raised for each data row (column or record). When calculating a group summary value for ASPxGridView, the event fires for each data row within the currently processed group.

Additionally, the event is raised before and after processing rows. This can be used to perform any initialization and finalization.

Use the GetValue(String) method to get the required value in the CustomSummaryCalculate event handler.

Note

  • The custom summary calculation option is not available in server mode. Please refer to the Data Binding to Large Data via XPO help topic for more information.
  • The CustomSummaryCalculate event is not raised on callbacks if the grid’s data is not updated.

Find control-specific information (for ASPxGridView, ASPxCardView or ASPxVerticalGrid) in the sections below.

#ASPxGridView

#Example

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;
}
protected void ASPxGridView1_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e) {
    if (e.Parameters == "Refresh")
        ASPxGridView1.DataBind();
}

Result:

GridView - CustomSummaryCalculate

#Online Demo

Run Demo: ASPxGridView - Export Selected Records

#ASPxCardView

#Example

protected void ASPxCardView1_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 (ASPxCardView1.Selection.IsCardSelectedByKey(e.GetValue(ASPxCardView1.KeyFieldName)))
            totalSum += Convert.ToInt32(e.FieldValue);
    }
    else
    // Finalization. 
    if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize)
        e.TotalValue = totalSum;
}
protected void ASPxCardView1_CustomCallback(object sender, DevExpress.Web.ASPxCardViewCustomCallbackEventArgs e) {
    if (e.Parameters == "Refresh")
        ASPxCardView1.DataBind();
}

Result:

CardView - CustomSummaryCalculate

#Online Demo

Run Demo: ASPxCardView - Export Selected Cards

#ASPxVerticalGrid

#Example

protected void ASPxVerticalGrid1_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 (ASPxVerticalGrid1.Selection.IsRecordSelectedByKey(e.GetValue(ASPxVerticalGrid1.KeyFieldName)))
            totalSum += Convert.ToInt32(e.FieldValue);
    }
    else
    // Finalization. 
    if (e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize)
        e.TotalValue = totalSum;
}
protected void ASPxVerticalGrid1_CustomCallback(object sender, DevExpress.Web.ASPxVerticalGridCustomCallbackEventArgs e) {
    if (e.Parameters == "Refresh")
        ASPxVerticalGrid1.DataBind();
}

VerticalGrid - CustomSummaryCalculate

See Also