【发布时间】: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,所以我必须首先对第一页的总数求和。如果我点击到第二页,那么我必须显示第二页的总数。如何实现?
【问题讨论】:
-
forums.asp.net/t/986566.aspx查看最后的回复。有了这个你应该弄清楚了。
标签: c# asp.net linq sql-server-2008 gridview