合并GridView中某列相同信息的行
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 写在公共模块里,定义为静态方法方便调用
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 写在公共模块里,定义为静态方法方便调用
作者:mFrog(mFrog的技术博客)
出处:http://mFrog.cnblogs.com/
本文版权由作者全部保留,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。