Gridview中某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容
1:
2: #region 合并单元格 合并某一行的所有列
3: /// <summary>
4: /// 合并GridView中某行相同信息的行(单元格)
5: /// </summary>
6: /// <param name="GridView1">GridView对象</param>
7: /// <param name="cellNum">需要合并的行</param>
8: public static void GroupRow(GridView GridView1, int rows)
9: {
10: TableCell oldTc = GridView1.Rows[rows].Cells[0];
11: for (int i = 1; i < GridView1.Rows[rows].Cells.Count; i++)
12: {
13: TableCell tc = GridView1.Rows[rows].Cells[i]; //Cells[0]就是你要合并的列
14: if (oldTc.Text == tc.Text)
15: {
16: tc.Visible = false;
17: if (oldTc.ColumnSpan == 0)
18: {
19: oldTc.ColumnSpan = 1;
20: }
21: oldTc.ColumnSpan++;
22: oldTc.VerticalAlign = VerticalAlign.Middle;
23: }
24: else
25: {
26: oldTc = tc;
27: }
28: }
29: }
30: #endregion
31: #region 合并单元格 合并一行中的几列
32: /// <summary>
33: /// 合并单元格 合并一行中的几列
34: /// </summary>
35: /// <param name="GridView1">GridView ID</param>
36: /// <param name="rows">行</param>
37: /// <param name="sCol">开始列</param>
38: /// <param name="eCol">结束列</param>
39: public static void GroupRow(GridView GridView1, int rows, int sCol, int eCol)
40: {
41: TableCell oldTc = GridView1.Rows[rows].Cells[sCol];
42: for (int i = 1; i < eCol - sCol; i++)
43: {
44: TableCell tc = GridView1.Rows[rows].Cells[i + sCol]; //Cells[0]就是你要合并的列
45: tc.Visible = false;
46: if (oldTc.ColumnSpan == 0)
47: {
48: oldTc.ColumnSpan = 1;
49: }
50: oldTc.ColumnSpan++;
51: oldTc.VerticalAlign = VerticalAlign.Middle;
52: }
53: }
54: #endregion
55: #region 合并单元格 合并某一列所有行
56: /// <summary>
57: /// 合并GridView中某列相同信息的行(单元格)
58: /// </summary>
59: /// <param name="GridView1"></param>
60: /// <param name="cellNum"></param>
61: public static void GroupCol(GridView GridView1, int cols)
62: {
63: if (GridView1.Rows.Count < 1 || cols > GridView1.Rows[0].Cells.Count - 1)
64: {
65: return;
66: }
67: TableCell oldTc = GridView1.Rows[0].Cells[cols];
68: for (int i = 1; i < GridView1.Rows.Count; i++)
69: {
70: TableCell tc = GridView1.Rows[i].Cells[cols];
71: if (oldTc.Text == tc.Text)
72: {
73: tc.Visible = false;
74: if (oldTc.RowSpan == 0)
75: {
76: oldTc.RowSpan = 1;
77: }
78: oldTc.RowSpan++;
79: oldTc.VerticalAlign = VerticalAlign.Middle;
80: }
81: else
82: {
83: oldTc = tc;
84: }
85: }
86: }
87: #endregion
88: #region 合并单元格 合并某一列中的某些行
89: /// <summary>
90: /// 合并单元格 合并某一列中的某些行
91: /// </summary>
92: /// <param name="GridView1">GridView ID</param>
93: /// <param name="cellNum">列</param>
94: /// <param name="sRow">开始行</param>
95: /// <param name="eRow">结束列</param>
96: public static void GroupCol(GridView GridView1, int cols, int sRow, int eRow)
97: {
98: if (GridView1.Rows.Count < 1 || cols > GridView1.Columns.Count - 1)
99: {
100: return;
101: }
102: TableCell oldTc = GridView1.Rows[sRow].Cells[cols];
103: for (int i = 1; i < eRow - sRow; i++)
104: {
105: TableCell tc = GridView1.Rows[sRow + i].Cells[cols];
106: tc.Visible = false;
107: if (oldTc.RowSpan == 0)
108: {
109: oldTc.RowSpan = 1;
110: }
111: oldTc.RowSpan++;
112: oldTc.VerticalAlign = VerticalAlign.Middle;
113: }
114: }
115: #endregion