Golf工作室

沧海中的一栗
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

Posted on 2009-09-02 09:50  Golf工作室  阅读(201)  评论(0编辑  收藏  举报
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;  //设置当前行的字体变粗,醒目!
        }
    }