Dynamically merge columns of DataRow in the GridView data row horizontally

Source: Internet
Author: User

Some time ago, Insus. NET had written "dynamic merge GridView data row DataRow column" http://www.cnblogs.com/insus/p/3238348.html, that is vertical (vertical) Merge a column.
In this case, we want to demonstrate how to dynamically merge the DataRow columns of the GridView data row horizontally. In the implementation process, refer to the previous article, the same principle.

Let's take a look at the http://www.cnblogs.com/insus/p/3303192.html of dynamic binding data (GridView control Header and ItemTemplate), which is the same for several consecutive columns of data in the first row. We merge the values of the same value into a column.

Add an event OnRowDataBound = "GridView1_RowDataBound" to the GridView control in html markup, as shown below:



Go to. aspx. cs to write the Event Logic Program:



The two variables cellIndex and mergeCellText are first declared to store the column index and column text.
# Row 61 indicates that only the first row of data is processed. If this line is Comment out, it means that all data is processed.
#70 lines of code are used to determine whether the column is the first.
# When the 76 rows are not the first column.
#88 rows are the last column.

In the following two animations, the comparison is made before merging and after merging:

Before merging:



After merging:

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.