for (int rowIndex = GVDCNoConfirm.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow currentRow = GVDCNoConfirm.Rows[rowIndex];
GridViewRow previousRow = GVDCNoConfirm.Rows[rowIndex + 1];
for (int i = 0; i < currentRow.Cells.Count; i++)
{
if (currentRow.Cells[i].Text == previousRow.Cells[i].Text)
{
if (previousRow.Cells[i].RowSpan < 2)
currentRow.Cells[i].RowSpan = 2;
else
currentRow.Cells[i].RowSpan = previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}
if (row.Cells[6].Text == previousRow.Cells[6].Text)
{
float currentvalue = 0;
currentvalue = Convert.ToSingle(row.Cells[5].Text);
float previousvalue = currentvalue + Convert.ToSingle(previousRow.Cells[5].Text);
row.Cells[5].Text = Convert.ToString(previousvalue);
previousRow.Cells[j].Visible = false;
}
}
}
我在RowDataBound中有这个代码用于合并gridview行。它的工作正常但是
sno name amount dcno
1 xxx 5000 888
2500 888
1000 1001
2 yyy 5250 1002
2000 555
1250 555
在这个网格中我要总和(5000 + 2500)= 7500,即相同的dcno 888和那样的(2000 + 1250)= 3250,即同样的dcno 555
所以我需要Out out like
sno name amount dcno
1 xxx 7500 888
1000 1001
2 yyy 5250 1002
3250 555
我试过这样但没有用,请任何人帮助我。
答案 0 :(得分:3)
您可以更改分组的DataSource。例如: 您当前的查询如下所示:
Items.Select(t => new {t.sno, t.name, t.amount, t.dcno})
新的将是:
Items.Select(t => new {t.sno, t.name, t.amount, t.dcno})
.GroupBy(t => new {t.sno, t.name, t.dcno})
.Select(t => new {t.Key.sno, t.Key.name, t.Key.dcno, amount = t.Sum(a => a.amount)}
希望这个帮助
答案 1 :(得分:0)
您不能在数据绑定之前准备源日期吗?如果我理解必须是&#39;组。在dcno提交,对吧?在这种情况下,您可以使用LINQ来准备数据。