The GRIDVIEW merges cells (merge columns) in multiple rows and columns, and the gridview merges multiple rows.

Source: Internet
Author: User

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.