Code
1 /// <summary>
2 /// 合并单元格方法
3 /// </summary>
4 /// <param name="iColumns">第几列数据相同</param>
5 private void MergeGridCell(int iColumns)
6 {
7 //合并的行数
8 int row;
9 //GridView行数
10 int col;
11 //从第几行开始合并
12 int count;
13 row = 0;
14 count = 0;
15 for (col = 1; col < this.GridView1.Rows.Count; col++)
16 {
17 if (GridView1.Rows[col - 1].Cells[iColumns].Text == GridView1.Rows[col].Cells[iColumns].Text)
18 {
19 row = row + 1;
20 GridView1.Rows[col].Cells[iColumns].Visible = false;
21 if (col == GridView1.Rows.Count - 1)
22 {
23 row = row + 1;
24 GridView1.Rows[count].Cells[iColumns].RowSpan = row;
25 count = 0;
26 }
27 }
28 else
29 {
30 GridView1.Rows[count].Cells[iColumns].RowSpan = row + 1;
31 row = 0;
32 count = col;
33 }
34 }
35 }
36
37
38
39 如果需要合并的列是模板列,就使用下面的方法。
40
41 //ControlID:模板列控件的ID
42
43 private void MergeGridTemplateCell(int iColumns,string ControlID) {
44 int row ;
45
46 int col ;
47 int count;
48 row = 0;
49 count = 0;
50 for (col = 1; col < this.GridView1.Rows.Count; col++)
51 {
52 if (((Literal)GridView1.Rows[col - 1].Cells[iColumns].FindControl(ControlID)).Text == ((Literal)GridView1.Rows[col].Cells[iColumns].FindControl(ControlID)).Text)//"litDay"
53 {
54 row = row + 1;
55 GridView1.Rows[col].Cells[iColumns].Visible = false;
56 if (col == GridView1.Rows.Count - 1)
57 {
58 row = row + 1;
59 GridView1.Rows[count].Cells[iColumns].RowSpan = row;
60 count = 0;
61 }
62 }
63 else
64 {
65 GridView1.Rows[count].Cells[iColumns].RowSpan = row + 1;
66 row = 0;
67 count = col;
68 }
69 }
70 }
71
72
1 /// <summary>
2 /// 合并单元格方法
3 /// </summary>
4 /// <param name="iColumns">第几列数据相同</param>
5 private void MergeGridCell(int iColumns)
6 {
7 //合并的行数
8 int row;
9 //GridView行数
10 int col;
11 //从第几行开始合并
12 int count;
13 row = 0;
14 count = 0;
15 for (col = 1; col < this.GridView1.Rows.Count; col++)
16 {
17 if (GridView1.Rows[col - 1].Cells[iColumns].Text == GridView1.Rows[col].Cells[iColumns].Text)
18 {
19 row = row + 1;
20 GridView1.Rows[col].Cells[iColumns].Visible = false;
21 if (col == GridView1.Rows.Count - 1)
22 {
23 row = row + 1;
24 GridView1.Rows[count].Cells[iColumns].RowSpan = row;
25 count = 0;
26 }
27 }
28 else
29 {
30 GridView1.Rows[count].Cells[iColumns].RowSpan = row + 1;
31 row = 0;
32 count = col;
33 }
34 }
35 }
36
37
38
39 如果需要合并的列是模板列,就使用下面的方法。
40
41 //ControlID:模板列控件的ID
42
43 private void MergeGridTemplateCell(int iColumns,string ControlID) {
44 int row ;
45
46 int col ;
47 int count;
48 row = 0;
49 count = 0;
50 for (col = 1; col < this.GridView1.Rows.Count; col++)
51 {
52 if (((Literal)GridView1.Rows[col - 1].Cells[iColumns].FindControl(ControlID)).Text == ((Literal)GridView1.Rows[col].Cells[iColumns].FindControl(ControlID)).Text)//"litDay"
53 {
54 row = row + 1;
55 GridView1.Rows[col].Cells[iColumns].Visible = false;
56 if (col == GridView1.Rows.Count - 1)
57 {
58 row = row + 1;
59 GridView1.Rows[count].Cells[iColumns].RowSpan = row;
60 count = 0;
61 }
62 }
63 else
64 {
65 GridView1.Rows[count].Cells[iColumns].RowSpan = row + 1;
66 row = 0;
67 count = col;
68 }
69 }
70 }
71
72