您的位置:首页 > 其它

GridView添加统计行 [转帖]

2008-12-18 19:29 204 查看
GridView添加统计(合计)行

前提:设置属性ShowFooter="True"

方法一:使用SQL查询统计出合计值,在绑定GridView时让其结果赋于一个DataTable(全局变量),然后在RowDataBound事件中

if (e.Row.RowType == DataControlRowType.Footer)
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();
}
}
转自:http://www.cnblogs.com/adam/archive/2007/03/30/694591.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: