Back to Devexpress

ASPxGridView.GetTotalSummaryValue(ASPxSummaryItem) Method

aspnet-devexpress-dot-web-dot-aspxgridview-dot-gettotalsummaryvalue-x28-devexpress-dot-web-dot-aspxsummaryitem-x29.md

latest9.6 KB
Original Source

ASPxGridView.GetTotalSummaryValue(ASPxSummaryItem) Method

Returns a summary value calculated against all data rows.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public object GetTotalSummaryValue(
    ASPxSummaryItem item
)
vb
Public Function GetTotalSummaryValue(
    item As ASPxSummaryItem
) As Object

Parameters

NameTypeDescription
itemASPxSummaryItem

An ASPxSummaryItem object that represents the summary item.

|

Returns

TypeDescription
Object

An object which represents the summary value.

|

Remarks

The ASPxGridView allows you to calculate summaries which are aggregate functions based on values of data source fields. There are two predefined summary types: the total and group summaries. The total summary calculates an aggregate function by all rows and displays the result in a column’s footer. The group summary calculates an aggregate function for each group of rows and displays the result in a group row. Both summary types are represented by a ASPxSummaryItem object.

Online Example

View Example: How to use group footer and footer templates to customize group and total summaries

Example

This sample illustrates how to calculate the total summary value based on values of other summaries

csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;

namespace WebApplication11 {
    public partial class _Default : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
        }

        protected void ASPxGridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) {
            ASPxSummaryItem incomeSummary = (sender as ASPxGridView).TotalSummary["Income"];
            ASPxSummaryItem expenseSummary = (sender as ASPxGridView).TotalSummary["Expense"];
            Decimal income = Convert.ToDecimal(((ASPxGridView)sender).GetTotalSummaryValue(incomeSummary));
            Decimal expense = Convert.ToDecimal(((ASPxGridView)sender).GetTotalSummaryValue(expenseSummary));
            e.TotalValue = income - expense;
        }

    }
}
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication11._Default" %>

<%@ register Assembly="DevExpress.Web.ASPxGridView.v9.1" Namespace="DevExpress.Web.ASPxGridView"
    TagPrefix="dxwgv" %>

<%@ Register assembly="DevExpress.Web.ASPxEditors.v9.1" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dxwgv:aspxgridview ID="ASPxGridView1" runat="server" 
            AutoGenerateColumns="False" DataSourceID="AccessDataSource1" 
            KeyFieldName="ID" 
            oncustomsummarycalculate="ASPxGridView1_CustomSummaryCalculate">
            <totalsummary>
                <dxwgv:aspxsummaryitem FieldName="Income" ShowInColumn="Income" 
                    SummaryType="Sum" />
                <dxwgv:aspxsummaryitem FieldName="Expense" ShowInColumn="Expense" 
                    SummaryType="Sum" />
                <dxwgv:aspxsummaryitem FieldName="Total" ShowInColumn="Total" 
                    SummaryType="Custom" />
            </totalsummary>
            <columns>
                <dxwgv:gridviewdatatextcolumn FieldName="Total" UnboundType="String" 
                    VisibleIndex="4">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatatextcolumn FieldName="ID" Visible="False" VisibleIndex="0">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatatextcolumn FieldName="Income" VisibleIndex="1">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatatextcolumn FieldName="Expense" VisibleIndex="2">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatadatecolumn FieldName="Date" VisibleIndex="3">
                </dxwgv:gridviewdatadatecolumn>
            </columns>
            <settings ShowFooter="True" />
        </dxwgv:aspxgridview>

    </div>
    <asp:accessdatasource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/Bookkeeper.mdb" SelectCommand="SELECT * FROM [Table1]">
    </asp:accessdatasource>
    </form>
</body>
</html>
aspx
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication11._Default" %>

<%@ register Assembly="DevExpress.Web.ASPxGridView.v9.1" Namespace="DevExpress.Web.ASPxGridView"
    TagPrefix="dxwgv" %>

<%@ Register assembly="DevExpress.Web.ASPxEditors.v9.1" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dxwgv:aspxgridview ID="ASPxGridView1" runat="server" 
            AutoGenerateColumns="False" DataSourceID="AccessDataSource1" 
            KeyFieldName="ID" 
            oncustomsummarycalculate="ASPxGridView1_CustomSummaryCalculate">
            <totalsummary>
                <dxwgv:aspxsummaryitem FieldName="Income" ShowInColumn="Income" 
                    SummaryType="Sum" />
                <dxwgv:aspxsummaryitem FieldName="Expense" ShowInColumn="Expense" 
                    SummaryType="Sum" />
                <dxwgv:aspxsummaryitem FieldName="Total" ShowInColumn="Total" 
                    SummaryType="Custom" />
            </totalsummary>
            <columns>
                <dxwgv:gridviewdatatextcolumn FieldName="Total" UnboundType="String" 
                    VisibleIndex="4">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatatextcolumn FieldName="ID" Visible="False" VisibleIndex="0">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatatextcolumn FieldName="Income" VisibleIndex="1">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatatextcolumn FieldName="Expense" VisibleIndex="2">
                </dxwgv:gridviewdatatextcolumn>
                <dxwgv:gridviewdatadatecolumn FieldName="Date" VisibleIndex="3">
                </dxwgv:gridviewdatadatecolumn>
            </columns>
            <settings ShowFooter="True" />
        </dxwgv:aspxgridview>

    </div>
    <asp:accessdatasource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/Bookkeeper.mdb" SelectCommand="SELECT * FROM [Table1]">
    </asp:accessdatasource>
    </form>
</body>
</html>
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxGridView

Namespace WebApplication11
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        End Sub

        Protected Sub ASPxGridView1_CustomSummaryCalculate(ByVal sender As Object, ByVal e As DevExpress.Data.CustomSummaryEventArgs)
            Dim incomeSummary As ASPxSummaryItem = (TryCast(sender, ASPxGridView)).TotalSummary("Income")
            Dim expenseSummary As ASPxSummaryItem = (TryCast(sender, ASPxGridView)).TotalSummary("Expense")
            Dim income As Decimal = Convert.ToDecimal((CType(sender, ASPxGridView)).GetTotalSummaryValue(incomeSummary))
            Dim expense As Decimal = Convert.ToDecimal((CType(sender, ASPxGridView)).GetTotalSummaryValue(expenseSummary))
            e.TotalValue = income - expense
        End Sub

    End Class
End Namespace

See Also

GetGroupSummaryValue(Int32, ASPxSummaryItem)

Grid View

Code Example T114923: ASPxGridView - How to update total summaries on the client side in Batch Edit mode

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace