Girdview 合并单元格 按日期合并我现在做的合并单元格,让重复的值合并但是我现在有个方法 我不会改希望高
Girdview 合并单元格 按日期合并
我现在做的合并单元格,让重复的值合并 但是我现在有个方法 我不会改 希望高手帮忙
C# code public static void MergeRows(GridView gridView) { for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--) { GridViewRow row = gridView.Rows[rowIndex]; GridViewRow previousRow = gridView.Rows[rowIndex + 1]; for (int i = 0; i < row.Cells.Count; i++) { if (row.Cells[i].Text == previousRow.Cells[i].Text) { row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 : previousRow.Cells[i].RowSpan + 1; previousRow.Cells[i].Visible = false; } } } }
在网上找的 只是重复的合并 没有按照时间
这个是 这个代码的效果
我想实现的效果
哪位高手帮帮忙
就有90分 全给了
[解决办法] 1/// <summary>
2 /// 合并GridView中某列相同信息的行(单元格)
3 /// </summary>
4 /// <param name="GridView1">GridView</param>
5 /// <param name="cellNum">第几列</param>
6 public static void GroupRows(GridView GridView1, int cellNum)
7 {
8 int i = 0, rowSpanNum = 1;
9 while (i < GridView1.Rows.Count - 1)
10 {
11 GridViewRow gvr = GridView1.Rows[i];
12
13 for (++i; i < GridView1.Rows.Count; i++)
14 {
15 GridViewRow gvrNext = GridView1.Rows[i];
16 if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
17 {
18 gvrNext.Cells[cellNum].Visible = false;
19 rowSpanNum++;
20 }
21 else
22 {
23 gvr.Cells[cellNum].RowSpan = rowSpanNum;
24 rowSpanNum = 1;
25 break;
26 }
27
28 if (i == GridView1.Rows.Count - 1)
29 {
30 gvr.Cells[cellNum].RowSpan = rowSpanNum;
31 }
32 }
33 }
34 }
35
36