asp gridview 统计总条数

时光毁灭记忆、已成空白 提交于 2020-03-27 10:02:58

 

先设置showfooter属性为true  再写一下代码

 

private double sum = 0;
private int sum1 = 0;
protected void GridView1_DataRowBinding(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowIndex > -1)
{
sum += Convert.ToDouble(e.Row.Cells[1].Text);
sum1 += Convert.ToInt32(e.Row.Cells[2].Text);
}
// 合计
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "总计" + GridView1.Rows.Count.ToString() + "条数据";
e.Row.Cells[1].Text = "总计发货金额:" + sum.ToString();
e.Row.Cells[2].Text ="总计发货数量:"+ sum1.ToString();

}
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!