原創(chuàng)|其它|編輯:郝浩|2012-11-06 16:35:50.000|閱讀 2436 次
概述:假設(shè)ASPxGridView網(wǎng)格控件被綁定到一個(gè)“Orders”數(shù)據(jù)表(NWIND數(shù)據(jù)庫),該數(shù)據(jù)表中包含了"UnitPrice", "Quantity" 和 "Discount" 等字段。雖然,在該表中沒有一個(gè)代表總和的字段,但是可以手動(dòng)計(jì)算如下:UnitPrice*Quantity*(1-Discount)。該示例展示了如何添加一個(gè)非綁定列到ASPxGridView中,以展示訂單SUM總和。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
假設(shè)ASPxGridView網(wǎng)格控件被綁定到一個(gè)“Orders”數(shù)據(jù)表(NWIND數(shù)據(jù)庫),該數(shù)據(jù)表中包含了"UnitPrice", "Quantity" 和 "Discount" 等字段。雖然,在該表中沒有一個(gè)代表總和的字段,但是可以手動(dòng)計(jì)算如下:UnitPrice*Quantity*(1-Discount)。該示例展示了如何添加一個(gè)非綁定列到ASPxGridView中,以展示訂單SUM總和。
C#
using DevExpress.Web.ASPxGridView; protected void ASPxGridView1_Init(object sender, EventArgs e) { // Creates a column, customizes its settings and appends it to the Columns collection; GridViewDataTextColumn colTotal = new GridViewDataTextColumn(); colTotal.Caption = "Total"; colTotal.FieldName = "Total"; colTotal.UnboundType = DevExpress.Data.UnboundColumnType.Integer; colTotal.VisibleIndex = ASPxGridView1.VisibleColumns.Count; colTotal.PropertiesTextEdit.DisplayFormatString = "c2"; ASPxGridView1.Columns.Add(colTotal); } // Populates the unbound column. protected void ASPxGridView1_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e) { if (e.Column.FieldName == "Total") { decimal unitPrice = Convert.ToDecimal(e.GetListSourceFieldValue("UnitPrice")); int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity")); decimal discount = Convert.ToDecimal(e.GetListSourceFieldValue("Discount")); e.Value = unitPrice * quantity * (1 - discount); }
VB
Imports DevExpress.Web.ASPxGridView Protected Sub ASPxGridView1_Init(ByVal sender As Object, ByVal e As System.EventArgs)_ Handles ASPxGridView1.Init ' Creates a column, customizes its settings and appends it to the Columns collection; Dim colTotal As GridViewDataTextColumn = New GridViewDataTextColumn() colTotal.Caption = "Total" colTotal.FieldName = "Total" colTotal.UnboundType = DevExpress.Data.UnboundColumnType.Integer colTotal.VisibleIndex = ASPxGridView1.VisibleColumns.Count colTotal.PropertiesTextEdit.DisplayFormatString = "c2" ASPxGridView1.Columns.Add(colTotal) End Sub ' Populates the unbound column. Protected Sub ASPxGridView1_CustomUnboundColumnData(ByVal sender As Object,_ ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs)_ Handles ASPxGridView1.CustomUnboundColumnData If e.Column.FieldName = "Total" Then Dim unitPrice As Decimal = Convert.ToDecimal(e.GetListSourceFieldValue("UnitPrice")) Dim quantity As Integer = Convert.ToInt32(e.GetListSourceFieldValue("Quantity")) Dim discount As Decimal = Convert.ToDecimal(e.GetListSourceFieldValue("Discount")) e.Value = unitPrice * quantity * (1 - discount) End If End Sub
結(jié)果如下:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:DevExpress中文網(wǎng)