ASPxGridView.GetTotalSummaryValue(ASPxSummaryItem) Method
Returns a summary value calculated against all data rows.
Namespace: DevExpress.Web
Assembly:
DevExpress.Web.v21.2.dll
NuGet Package:
DevExpress.Web
Declaration
public object GetTotalSummaryValue(
ASPxSummaryItem item
)
Public Function GetTotalSummaryValue(
item As ASPxSummaryItem
) As Object
Parameters
Returns
Type |
Description |
Object |
An object which represents the summary value.
|
The ASPxGridView enables 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.
Example
This sample illustrates how to calculate the total summary value based on values of other summaries
View Example
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;
}
}
}
<%@ 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>
<%@ 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>
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