gridview 合计行实现

本文详细介绍了如何在GridView中实现数据汇总功能,包括点击数、IP数、金额、通话次数、订单数量、接收金额和接收数量的计算,并在表格的底部显示合计。通过编程实现在每行数据绑定时累加所需字段的值,最终在footer中显示总计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1:首先给gridview添加ShowFooter="true" 属性

2:在RowDataBound 实现数据合计

 

protected override void OnMainGridRowDataBound(object sender, GridViewRowEventArgs e)     {        

base.OnMainGridRowDataBound(sender, e);

 if (e.Row.RowType == DataControlRowType.DataRow)        

    {             

 clickcount += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PVCount"));            

ipconut += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "IPCount"));            

amoutcount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "AmountQR"));            

talkcount += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "talkCount"));            

ordercount += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "CountQR"));            

shouamount += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "AmountQS"));            

shoucount += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "CountQS"));

}        

else if (e.Row.RowType == DataControlRowType.Footer)        

{            

e.Row.Cells[0].Text = "合计";            

e.Row.Cells[4].Text = clickcount.ToString();            

e.Row.Cells[5].Text = ipconut.ToString();            

e.Row.Cells[6].Text = amoutcount.ToString("0.00");            

e.Row.Cells[7].Text = talkcount.ToString();            

e.Row.Cells[8].Text = ordercount.ToString();            

e.Row.Cells[9].Text = shouamount.ToString();            

e.Row.Cells[10].Text = shoucount.ToString();            

e.Row.Font.Bold = true;        

}

    }

转载于:https://www.cnblogs.com/EDSON/archive/2013/05/24/3096498.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值