GridView增加一个统计行的方法《原创》

2008-07-27 16:11
根据网上收集的资料,实现的方式比较多,推荐这种方式,比较好用! 
   private int sum1,sum2;  //全局变量
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
               if (e.Row.RowType == DataControlRowType.DataRow)
        {
            sum1 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Salery"));
            sum2 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Count"));
        }
       
        // 合计
        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.Font.Bold = true;  //设置当前行的字体变粗,醒目!
        }
    }
原文地址:https://www.cnblogs.com/Golf9527/p/1558519.html