关于计算GridView单元格内值的和 问题是这样的,一个GridView,我用2个FOR循环(调用存储过程)将值插入GridView的每一个单元格中我现在想在每一行和每一列的最后一个单元格计算出这一行和这一列的和请问在数据库中怎么实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach(gridviewrow row in grd.rows){ int r=0; for (i=0;i<=5;i++) //假设有6列要统计到第七列 { r+=int.parse(row.cells[i].text); } row.cells[i].text=r.tostring();} private double sum = 0;//取指定列的数据和,你要根据具体情况对待可能你要处理的是intprotected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex >= 0) { sum += Convert.ToDouble(e.Row.Cells[6].Text); } 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(); } }前台:唯一的花头就是设置ShowFooter="True" ,否则默认表头为隐藏的! 数据库里聚集表达式 SUM再GROUP BY吧~ 这句sql语句怎么不对? 怎么获取用户的ip和当前所在地址? 一个aspx页面的CS变量如何传给html页面? 新手提问!头疼的表格布局。。。! atlas工具包哪里有的下呀 菜鸟求救????怎么老显这个错误??? 创建目录的问题? 这到底是怎么回事? 产品保护问题 asp:TreeView 选中子节点取值bug GridView的TemplateField问题 用String.Format还是StringBuilder的Append哪个资源消耗少??如何测试运行速度啊?
{
int r=0;
for (i=0;i<=5;i++) //假设有6列要统计到第七列
{
r+=int.parse(row.cells[i].text);
}
row.cells[i].text=r.tostring();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
sum += Convert.ToDouble(e.Row.Cells[6].Text);
}
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();
}
}
前台:唯一的花头就是设置ShowFooter="True" ,否则默认表头为隐藏的!
聚集表达式 SUM
再GROUP BY吧~