protected void inderGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal rowTotal = Convert.ToDecimal
(DataBinder.Eval(e.Row.DataItem, "DC_No_Decimal"));
//grdTotal = grdTotal + rowTotal;
grdTotal += rowTotal;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblTotal");
e.Row.Cells[3].Text = grdTotal.ToString("c");
//lbl.Text = grdTotal.ToString("c");
}
}从上面的代码中,我得到了网格视图中每个页面的总数。而不是让总数到每一页,我需要所有的页面总数在网格视图页脚的结尾。立即提供帮助。提前感谢
发布于 2011-11-02 19:11:07
如果你想要所有页面的总数,并且页脚只出现在最后一页,那么你不能计算你正在做的事情的总数。
在你遍历网格视图的每一行的那一刻。如果您使用分页,网格视图将不会显示所有行,因此总数将不正确。
您是使用PagedDataSource分页,还是限制从SQL等返回的记录?如果您使用的是DataSet和PagedDataSource,您将能够从DataSet中找到总数(因为它将包含所有记录)。否则,您将不得不创建第二个查询来计算总数。
然后,就在页脚中显示值而言,您必须向ItemDataBound事件添加一条IF语句,以便仅在最后一个页面显示此内容。
发布于 2011-11-02 18:55:20
不知道,但您可以在if条件下再尝试一次检查。
if(e.Row.RowType == DataControlRowType.Footer && inderGrid.PageCount == inderGrid.PageIndex + 1)
{
//code here.
}//试试这个
if(e.Row.RowType == DataControlRowType.Footer && inderGrid.PageCount == inderGrid.PageIndex + 1)
{
for (int i=0; i< inderGrid.Rows.Count; i++)
{
var currentRowCellVal = Convert.ToDecimal(inderGrid.Rows[i].Cells[0].Text);
grdTotal += currentRowCellVal;
}
e.Row.Cells[3].Text = grdTotal.ToString("c");
}发布于 2011-11-02 18:57:35
如果您想要显示摘要记录,请查看以下关于Displaying Summary Information in the GridView's Footer的记录
https://stackoverflow.com/questions/7990661
复制相似问题