GridView Add Statistics FooterRow

  遍历所有行,获取对应行对应列值的统计,此函数写在RowDataBind事件中 
 int mysum1 = 0
    
int mysum2 = 0;
    
protected void GridList_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow )
        
{
            DataRowView myrows
=(DataRowView)e.Row.DataItem;
            mysum1 
+=Convert .ToInt32 (myrows[2].ToString ());
            mysum2 
+= Convert.ToInt32(myrows[3].ToString());
        }

        
// 合计
        if (e.Row.RowType == DataControlRowType.Footer)
        
{
            e.Row.Cells[
0].Text = "合计";
            e.Row.Cells[
1].Text = mysum1.ToString();
            e.Row.Cells[
2].Text = mysum2.ToString();
        }

    }

posted @ 2007-04-04 17:13 DavidYou Views(119) Comments(0) Edit 收藏