您的位置:首页 > 其它

GridView自动求和、求平均值小计[转]

2012-06-07 16:05 323 查看
转自清清月儿gridview72绝技,略有改动

前台:唯一的花头就是设置ShowFooter="True"

private double sum = 0;//取指定列的数据和,你要根据具体情况对待可能你要处理的是int
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
sum += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "dateTimeAll").ToString());

}

else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[5].Text = "总薪水为:";
e.Row.Cells[6].Text = sum.ToString();
e.Row.Cells[3].Text = "平均薪水为:";
e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: