gridview 添加汇总行 footer
//----------------------------------------------------------------------------------
添加属性 showfooter=true
找到控件的 grdList_RowDataBound 事件
protected void grdList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 添加汇总行 20130923
//---------------------------------------------------------------------
count1 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "count1"));
count2 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "count2"));
count3 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "count3"));
//---------------------------------------------------------------------
if (CurrentUser.RegionDetailType != 1)
{
e.Row.Cells[0].Text = "";
}
}
// 添加汇总行 20130923
//---------------------------------------------------------------------
if (e.Row.RowType == DataControlRowType.Footer)
{
//e.Row.Cells[0].Text = "合计";
e.Row.Cells[1].Text = "合计";
e.Row.Cells[2].Text = count1.ToString();
e.Row.Cells[3].Text = count2.ToString();
e.Row.Cells[4].Text = count3.ToString();
e.Row.Font.Bold = true;
}
//---------------------------------------------------------------------
}
本文介绍如何在ASP.NET的GridView控件中添加汇总行。通过设置showFooter属性为true,并利用grdList_RowDataBound事件来实现对指定列的求和操作。在事件处理中遍历每一行的数据并进行累加,最后在Footer类型行显示汇总结果。

6326

被折叠的 条评论
为什么被折叠?



