使用ActiveReports for .net 进行报表开发(八)显示合计

在报表开发中我们常常要显示合计,比如销售记录,要显示单价,售出件数,合计金额等。

我们可以在从数据库中提取数据的时候就使用SQL来产生一个合计字段,也可以在ActiveReport中进行,有两种方法可以使用。

1.       使用ActiveReport中的LabelTextBox控件的DataField属性。例如,要使一个TextBox显示合计,它的值是由单价和售出件数的乘积。设置TextBoxDataField值为“=单价*售出件数”。然后编写代码,加载数据,设置Field集合,然后在FetchData事件中给Field赋值,就可以完成了,例如:

this.Fields["ProductName"].Value = row.productName;

this.Fields["UnitPrice"].Value = row.unitPrice;

this.Fields["Quantity"].Value = row.quantity;

2.       不对DataField属性使用表达式,而是直接在FetchData中进行计算,例如:

double quantity = Convert.ToDouble(this.Fields["Quantity"].Value);

double unitPrice = Convert.ToDouble(this.Fields["UnitPrice"].Value);

this.Fields["ExtendedPrice"].Value =  quantity * unitPrice;

当然要在报表上显示要设置LabelTextBoxDataField属性为ExtendedPrice

原文地址:https://www.cnblogs.com/dahuzizyd/p/ActiveReports_8.html