ITPub博客

首页 > IT职业 > IT图书 > 如何在GridView的Footer内显示总计

如何在GridView的Footer内显示总计

IT图书 作者:ewen321 时间:2021-09-09 09:14:55 0 删除 编辑

前台:


    

    


后台:

private int num = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRowView dr = e.Row.DataItem as DataRowView;
        num += Convert.ToInt32(dr.Row["first"]);
    }
    else if (e.Row.RowType == DataControlRowType.Footer)
    {
       Label LabelAll =  e.Row.FindControl("labelAll") as Label;
       if (LabelAll != null)
       {
           LabelAll.Text += num.ToString();//"计算的总数,或者也可以单独计算";//
       }
    }
}

"first"是数据源的一个字段

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4325/viewspace-2801169/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-12

  • 博文量
    65
  • 访问量
    639