The GRIDVIEW merges cells (merge columns) in multiple rows and columns, and the gridview merges multiple rows.
GitHub address: https://github.com/mingceng/merge-gridviewcell
Two articles: combining cells with multiple rows and columns in the GridView (complete code and example) and merging cells with multiple rows and columns in the GridView (specifying column merging ). To add more features today, first look:
1: /// <summary>
2: // and parallel
3: /// </summary>
4: /// <param name = "gv"> the GridView to be merged </param>
5: /// <param name = "startCol"> Start column index </param>
6: // <param name = "endCol"> end column index </param>
7: // <param name = "containHeader"> whether to merge the header. By default, the header is not merged. </param>
8: public static void MergeColumn(GridView gv, int startCol, int endCol, bool containHeader = false)
9: {
10: if (containHeader)
11: {
12: BLRowCells(gv.HeaderRow, startCol, endCol);
13: }
14: foreach (GridViewRow row in gv.Rows)
15: {
16: BLRowCells(row, startCol, endCol);
17: }
18: }
19:
20: /// <summary>
21: // traverse the cells in GridViewRow
22: /// </summary>
23: // <param name = "row"> row to be traversed </param>
24: // <param name = "start"> start index </param>
25: // <param name = "end"> end index </param>
26: private static void BLRowCells(GridViewRow row, int start, int end)
27: {
28: // starting from the next column of the Start Index
29: for (int i = start + 1; i <= end; i++)
30: {
31: // current cell
32: TableCell currCell = row.Cells[i];
33: // previous cell
34: TableCell prevCell = row.Cells[i - 1];
35: if (!string.IsNullOrEmpty(currCell.Text) && !string.IsNullOrEmpty(prevCell.Text))
36: {
37: if (currCell.Text == prevCell.Text)
38: {
39: currCell.ColumnSpan = prevCell.ColumnSpan < 1 ? 2 : prevCell.ColumnSpan + 1;
40: prevCell.Visible = false;
41: }
42: }
43: }
44: }
As a continuation of the previous two articles, this article is relatively simple, but it may be helpful if you need to merge the GridView cells!
GitHub address: https://github.com/mingceng/merge-gridviewcell
Source: Http://www.cnblogs.com/nianming/