确保WCF服务返回的数据包含总计。
在客户端调用WCF服务时,使用LINQ查询来计算总计,并将其保存到一个变量中。
将计算出的总计值添加到网格视图控件的底部行中:
protected decimal GetTotal()
{
// Calling the service
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
var data = client.GetData();
// Calculating the total
decimal total = (from d in data
select d.Amount).Sum();
return total;
}
这样,就可以通过WCF服务实现在网格视图控件中显示总计。