<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True"
OnRowDataBound="gv_RowDataBound" ShowFooter="True">
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
sum1 += Convert.ToInt32(e.Row.Cells[1].Text);
sum2 += Convert.ToInt32(e.Row.Cells[2].Text);
sum3 += Convert.ToInt32(e.Row.Cells[3].Text);
sum4 += Convert.ToInt32(e.Row.Cells[4].Text);
sum5 += Convert.ToInt32(e.Row.Cells[5].Text);
sum6 += Convert.ToInt32(e.Row.Cells[6].Text);
sum7 += Convert.ToInt32(e.Row.Cells[7].Text);
}else if (e.Row.RowType == DataControlRowType.Footer)
{ //判断此行是否是页尾,如果是则开始统计数据
e.Row.Cells[0].Text = "合计";//每一列的数
e.Row.Cells[1].Text = sum1.ToString();//合计值
e.Row.Cells[2].Text = sum2.ToString();//合计值
e.Row.Cells[3].Text = sum3.ToString();//合计值
e.Row.Cells[4].Text = sum4.ToString();//合计值
e.Row.Cells[5].Text = sum5.ToString();//合计值
e.Row.Cells[6].Text = sum6.ToString();//合计值
e.Row.Cells[7].Text = sum7.ToString();//合计值
}
}