【发布时间】:2014-08-12 17:10:18
【问题描述】:
我想总结 gridview 中的两列并在标签中显示总数。我在 gridview 中启用了分页。
使用此代码,我将两列的总数相加,但是,总数仅适用于所选页面。
如何进行总计来汇总所有页面中选定列的所有行?
decimal priceTotal = 0;
int totalMinutes = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Total"));
totalMinutes += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Duration"));
}
lblTotalPrice.Text = "Total Cost: $"+ priceTotal.ToString();
lblTotalMinutes.Text = "Total duration: " + totalMinutes.ToString();
}
【问题讨论】:
-
我有,但我只是不想调用另一个查询或过程来返回总和,因为我知道我可以遍历 gridview。