int mysum1 = 0;
int mysum2 = 0;
protected void GridList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
DataRowView myrows=(DataRowView)e.Row.DataItem;
mysum1 +=Convert .ToInt32 (myrows[2].ToString ());
mysum2 += Convert.ToInt32(myrows[3].ToString());
}
// 合计
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "合计";
e.Row.Cells[1].Text = mysum1.ToString();
e.Row.Cells[2].Text = mysum2.ToString();
}
}
本文介绍在ASP.NET中如何使用GridView控件的RowDataBound事件进行数据行的遍历,实现对指定列的数据进行求和统计,并在页脚显示总计。通过将数据转换为整数并累加,最后在Footer行显示合计数值。

2万+

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



