先设置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();
}
}