datagirdview的求和问题

chaye12 2008-07-10 10:23:32
我的datagridview是有N列,由N个数据表通过联合查询以及自定义的方式组合成的,我想在最后加上一列,这列的值为前面几列的数值的和,列数不确定,因为列数可能会增多,请问该如何去做?
...全文
53 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wocow2316 2008-07-10
  • 打赏
  • 举报
回复
把datagridview 和一个DataSet 绑定
改变 DataSet 的值就可以
Maxlusune 2008-07-10
  • 打赏
  • 举报
回复
double[] sum = new double[14];
protected void exGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[11].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow )//如果行类型是"数据行"
{

sum[0] += double.Parse(e.Row.Cells[2].Text);
sum[2] += double.Parse(e.Row.Cells[3].Text);
sum[3] += double.Parse(e.Row.Cells[4].Text);
sum[4] += double.Parse(e.Row.Cells[5].Text);
sum[5] += double.Parse(e.Row.Cells[6].Text);
sum[6] += double.Parse(e.Row.Cells[7].Text);
sum[7] += double.Parse(e.Row.Cells[8].Text);
sum[8] += double.Parse(e.Row.Cells[9].Text);
sum[9] += double.Parse(e.Row.Cells[10].Text);
sum[10] += double.Parse(e.Row.Cells[11].Text);
e.Row.Cells[12].Text = e.Row.Cells[11].Text;
e.Row.Cells[11].Visible = false;
sum[11] += double.Parse(e.Row.Cells[13].Text);
sum[12] += double.Parse(e.Row.Cells[14].Text);
sum[13] += double.Parse(e.Row.Cells[15].Text);

}

if (e.Row.RowType == DataControlRowType.Footer)
{

e.Row.Cells[0].Text = "合计:";
e.Row.Cells[2].Text = sum[0].ToString();
e.Row.Cells[3].Text = sum[2].ToString();
e.Row.Cells[4].Text = sum[3].ToString();
e.Row.Cells[5].Text = sum[4].ToString();
e.Row.Cells[6].Text = sum[5].ToString();
e.Row.Cells[7].Text = sum[6].ToString();
e.Row.Cells[8].Text = sum[7].ToString();
e.Row.Cells[9].Text = sum[8].ToString();
e.Row.Cells[10].Text = sum[9].ToString();
e.Row.Cells[11].Text = sum[10].ToString();
e.Row.Cells[11].Visible = false;
((TextBox)e.Row.Cells[12].FindControl("tb122")).Visible = true;
e.Row.Cells[13].Text = sum[11].ToString();
e.Row.Cells[14].Text = sum[12].ToString();
e.Row.Cells[15].Text=sum[13].ToString();


}
}

110,825

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧