使用ActiveReports for .net 进行报表开发(八)--显示合计
2007-11-20 20:55
423 查看
在报表开发中我们常常要显示合计,比如销售记录,要显示单价,售出件数,合计金额等。
我们可以在从数据库中提取数据的时候就使用SQL来产生一个合计字段,也可以在ActiveReport中进行,有两种方法可以使用。
1. 使用ActiveReport中的Label或TextBox控件的DataField属性。例如,要使一个TextBox显示合计,它的值是由单价和售出件数的乘积。设置TextBox的DataField值为“=单价*售出件数”。然后编写代码,加载数据,设置Field集合,然后在FetchData事件中给Field赋值,就可以完成了,例如:
[align=left]this.Fields["ProductName"].Value = row.productName;[/align]
[align=left]this.Fields["UnitPrice"].Value = row.unitPrice;[/align]
this.Fields["Quantity"].Value = row.quantity;
2. 不对DataField属性使用表达式,而是直接在FetchData中进行计算,例如:
[align=left]double quantity = Convert.ToDouble(this.Fields["Quantity"].Value);[/align]
[align=left]double unitPrice = Convert.ToDouble(this.Fields["UnitPrice"].Value);[/align]
this.Fields["ExtendedPrice"].Value = quantity * unitPrice;
当然要在报表上显示要设置Label或TextBox的DataField属性为ExtendedPrice
我们可以在从数据库中提取数据的时候就使用SQL来产生一个合计字段,也可以在ActiveReport中进行,有两种方法可以使用。
1. 使用ActiveReport中的Label或TextBox控件的DataField属性。例如,要使一个TextBox显示合计,它的值是由单价和售出件数的乘积。设置TextBox的DataField值为“=单价*售出件数”。然后编写代码,加载数据,设置Field集合,然后在FetchData事件中给Field赋值,就可以完成了,例如:
[align=left]this.Fields["ProductName"].Value = row.productName;[/align]
[align=left]this.Fields["UnitPrice"].Value = row.unitPrice;[/align]
this.Fields["Quantity"].Value = row.quantity;
2. 不对DataField属性使用表达式,而是直接在FetchData中进行计算,例如:
[align=left]double quantity = Convert.ToDouble(this.Fields["Quantity"].Value);[/align]
[align=left]double unitPrice = Convert.ToDouble(this.Fields["UnitPrice"].Value);[/align]
this.Fields["ExtendedPrice"].Value = quantity * unitPrice;
当然要在报表上显示要设置Label或TextBox的DataField属性为ExtendedPrice
相关文章推荐
- 使用ActiveReports for .net 进行报表开发(八)--显示合计 (转)
- 使用ActiveReports for .net 进行报表开发(八)--显示合计
- 使用ActiveReports for .net 进行报表开发(八)--显示合计
- 使用ActiveReport for .net 进行报表开发(三)--显示对象集合中的数据
- 使用ActiveReport for .net 进行报表开发(四)—显示主从表
- 使用ActiveReports for .net 进行报表开发(十)--交叉变换背景
- 使用ActiveReports for .net 进行报表开发(六)--导出报表 (转)
- 使用ActiveReports for .net 进行报表开发(九)--End User
- 使用ActiveReports for .net 进行报表开发(十)--交叉变换背景
- 使用ActiveReports for .net 进行报表开发(五)—交叉报表
- 使用ActiveReports for .net 进行报表开发(五)—交叉报表
- 使用ActiveReports for .net 进行报表开发-交叉报表
- 使用ActiveReports for .net 进行报表开发(七)--事件 (转)
- 使用ActiveReports for .net 进行报表开发(五)—交叉报表
- 使用ActiveReport for .net 进行报表开发(四)—显示主从表
- 使用ActiveReports for .net 进行报表开发(六)--导出报表
- 使用ActiveReports for .net 进行报表开发(十一)--迁移到3.0
- 使用ActiveReports for .net 进行报表开发(十一)--迁移到3.0
- 使用ActiveReports for .net 进行报表开发--交叉变换背景
- 使用ActiveReports for .net 进行报表开发(九)--End User (转)