GridView加入自动求和求平均值小计

 

 1     private double sum = 0;//取指定列的数据和,你要根据具体情况对待可能你要处理的是int
 2     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 3     {
 4         
 5         if (e.Row.RowIndex >= 0)
 6         {
 7             sum += Convert.ToDouble(e.Row.Cells[6].Text);
 8         }
 9         else if (e.Row.RowType == DataControlRowType.Footer)
10         {
11             e.Row.Cells[5].Text = "总薪水为:";
12             e.Row.Cells[6].Text = sum.ToString();
13             e.Row.Cells[3].Text = "平均薪水为:";
14             e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();
15             
16         }
17     }
18 
19 
posted on 2008-08-14 10:22  kevin.Cheng  阅读(607)  评论(1)    收藏  举报