【发布时间】:2015-05-12 14:51:20
【问题描述】:
我正在尝试动态汇总列并添加为标签。
我有一个名为“GrdDynamic”的网格视图
GrdDynamic_RowDataBound
protected void GrdDynamic_RowDataBound(object sender, GridViewRowEventArgs e)
{
int total = 0;
if (e.Row.RowType == DataControlRowType.Footer)
{
foreach (GridViewRow row in GrdDynamic.Rows)
{
for (int i = 6; i <= GrdDynamic.Columns.Count; i++)
{
if (!string.IsNullOrEmpty(row.Cells[i].Text))
{
total = total + Convert.ToInt32(row.Cells[i].Text);
}
Label label = new Label();
e.Row.Cells[i].Text = total.ToString();
label.Text = "total" + " " + total;
e.Row.Cells[i].Controls.Add(label);
}
}
}
}
我需要在 6. 列之后根据每一列动态求和。
作为实例:
如果我有 10 列
我必须从 6. 列到 10. 列求和,如下所示
6. column sum is 500
7. column sum is 350
8. column sum is 150
9. column sum is 100
10.column sum is 330
如何在代码方面做到这一点
我们将不胜感激。
谢谢。
【问题讨论】:
-
什么是aspx,什么是数据源?另外,除了您从第 7 列开始之外,您当前的方法有什么问题?