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: