实用技巧

关注公众号 jb51net

关闭
首页 > 网络编程 > ASP.NET > 实用技巧 > Gridview 汇总

asp.net Gridview里添加汇总行

作者:

在rowdatabound事件里添加同时showfooter设为true

if (e.Row.RowType == DataControlRowType.DataRow)
{
totalcash += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "cash"));
totalunbalanced += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "unbalanced"));
totalsettled += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "settled"));
}
else if(e.Row .RowType ==DataControlRowType .Footer )
{
e.Row.Cells[0].Text = "合计";
e.Row.Cells[1].Text = totalcash.ToString("0.00");
e.Row.Cells[2].Text = totalunbalanced.ToString("0.00");
e.Row.Cells[3].Text = totalsettled.ToString("0.00");
e.Row.Font.Bold = true;
}

您可能感兴趣的文章:
阅读全文