彩票走势图

ASPxGridView控件常用示例一:添加一个非绑定列

原创|其它|编辑:郝浩|2012-11-06 16:35:50.000|阅读 2398 次

概述:假设ASPxGridView网格控件被绑定到一个“Orders”数据表(NWIND数据库),该数据表中包含了"UnitPrice", "Quantity" 和 "Discount" 等字段。虽然,在该表中没有一个代表总和的字段,但是可以手动计算如下:UnitPrice*Quantity*(1-Discount)。该示例展示了如何添加一个非绑定列到ASPxGridView中,以展示订单SUM总和。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

假设ASPxGridView网格控件被绑定到一个“Orders”数据表(NWIND数据库),该数据表中包含了"UnitPrice", "Quantity" 和 "Discount" 等字段。虽然,在该表中没有一个代表总和的字段,但是可以手动计算如下:UnitPrice*Quantity*(1-Discount)。该示例展示了如何添加一个非绑定列到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

结果如下:


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:DevExpress中文网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP