DataGrid 汇总行

定义保存变量保存汇总值 
 private double myTotalMoney;
 private double myTotalNum;


在ItemDataBound中处理事件(由于在Footer中显示,必须设置Footer可见)

None.gif  private void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif  
dot.gif{
InBlock.gif   
switch ((int)(e.Item.ItemType))
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
case (int)ListItemType.Item :
InBlock.gif    
case (int)ListItemType.AlternatingItem: 
InBlock.gif     
//Calculate total for the field of each row and alternating row.
InBlock.gif
     myTotalNum += Convert.ToDouble(e.Item.Cells[3].Text);
InBlock.gif     myTotalMoney 
+= Convert.ToDouble(e.Item.Cells[4].Text);
InBlock.gif     
//Format the data, and then align the text of each cell to the right.
InBlock.gif
     e.Item.Cells[4].Text = Convert.ToDouble(e.Item.Cells[4].Text).ToString("##,##0.00");  
InBlock.gif     e.Item.Cells[
4].Attributes.Add("align""right");
InBlock.gif     
break;
InBlock.gif    
case (int)ListItemType.Footer:
InBlock.gif     
//Use the footer to display the summary row.
InBlock.gif
     e.Item.Cells[1].Text = "总 计";
InBlock.gif     e.Item.Cells[
1].Attributes.Add("align""left");
InBlock.gif     e.Item.Cells[
3].Attributes.Add("align""left");
InBlock.gif     e.Item.Cells[
4].Attributes.Add("align""right");
InBlock.gif     e.Item.Cells[
3].Text = myTotalNum.ToString();
InBlock.gif     e.Item.Cells[
4].Text = myTotalMoney.ToString("c");
InBlock.gif     
break;
ExpandedSubBlockEnd.gif   }

InBlock.gif
ExpandedBlockEnd.gif  }

None.gif

转载于:https://www.cnblogs.com/opendr/archive/2006/10/14/528736.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值