gridview单元格合并并合并行 [英] gridview cells merging and sum merged rows
本文介绍了gridview单元格合并并合并行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 ]。文字== previousRow .Cells [ 6 ]。文本)
{
float currentvalue = 0 跨度>;
currentvalue = Convert.ToSingle(row.Cells [ 5 ]。Text);
float previousvalue = currentvalue + Convert.ToSingle(previousRow.Cells [ 5 ]。文字) ;
row.Cells [ 5 ]。Text = Convert.ToString(previousvalue);
previousRow.Cells [j] .Visible = false ;
}
}
}
我在RowDataBound中有此代码用于合并gridview行。工作正常但是
sno名称数量dcno
1 xxx 5000 888
2500
1000 1001
2 yyy 5250 1002
2000 555
1250 555
在这个网格中我要求(5000 + 2500)= 7500即相同的dcno 888和那样(2000 + 1250)= 3250即同样的dcno 555
所以我需要Out to like
sno name amount dcno
1 xxx 7500 888
1000 1001
2 yyy 5250 1002
3250 555
解决方案
如果您正在谈论余额查询,请查看此处:在SQL Server查询中运行总计 [ ^ ]
更多关于Google [ ^ ]!
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;
}
}
}
I have this code in RowDataBound for merging gridview rows. Its working fine But
sno name amount dcno
1 xxx 5000 888
2500
1000 1001
2 yyy 5250 1002
2000 555
1250 555
In this grid I want to sum (5000+2500)=7500 i.e same dcno 888 and like that (2000+1250)=3250 i.e same dcno 555
So I need Out put like
sno name amount dcno
1 xxx 7500 888
1000 1001
2 yyy 5250 1002
3250 555
解决方案
If you're talking about "balance query", have a look here: Running totals in SQL Server queries[^]
More on Google[^]!
这篇关于gridview单元格合并并合并行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文