【问题标题】:Gridview Footer total using Linq使用 Linq 的 Gridview 页脚总数
【发布时间】:2015-02-12 00:44:30
【问题描述】:

我使用此代码对列值求和

int total = 0;
protected void gvEmp_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Amount"));
}
if(e.Row.RowType==DataControlRowType.Footer)
{
Label lblamount = (Label)e.Row.FindControl("lblTotal");
lblamount.Text = total.ToString();
}
}

我的数据库中有更多数据。所以我决定使用下面的Linq Query

GridView1.Columns[8].FooterText = (from row in dt.AsEnumerable()
                                   select row.Field<int>("amount")).Sum().ToString(); 

但我的网格中有分页,页面大小为 50,所以我必须首先对第一页的总数求和。如果我点击到第二页,那么我必须显示第二页的总数。如何实现?

【问题讨论】:

标签: c# asp.net linq sql-server-2008 gridview


【解决方案1】:

试试这个:

GridView1.Columns[8].FooterText = (from row in dt.AsEnumerable()
                                   select row.Field<int>("amount")).Skip(GridView1.PageIndex * GridView1.PageSize).Take(GridView1.PageSize).Sum().ToString();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 2013-12-08
    • 1970-01-01
    • 2011-04-21
    • 2015-12-01
    • 2011-08-12
    相关资源
    最近更新 更多