给GridView增加求和行

1、在WebForm窗体中,设置GridView的ShowFooter="True"

2、在后台代码中

private int jhrs=0,ybrs=0;//定义变量

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowIndex >= 0)

{

jhrs += Convert.ToInt16(e.Row.Cells[4].Text);

ybrs += Convert.ToInt16(e.Row.Cells[5].Text);

}

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

{

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

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

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

}

}

 

posted @ 2015-09-23 15:36  xashxsy  阅读(354)  评论(0编辑  收藏  举报