The previous version of the dynamic merge Repeater control data column http://www.cnblogs.com/insus/p/3240848.html.
Today, Insus. NET re-demonstrated it. Why? Because two points are required to be rewritten. First, the column code generated by cs is redundant. Second, exceptions may occur during merging. What should I do? In this example, the data of the columns to be merged is just continuous. At that time, the same data is calculated for statistics. If the data is not continuous and the same data is also counted, this exception can be imagined.
This article uses the initial code to solve the problem above. In addition, it uses the new calculation method to merge column statistics.
Html markup focuses on the highlight part.
Go to the. aspx. cs Write Program and first create a class, which will be the basic object of the merged column.
Create another class to process the data of the merged columns and calculate the same continuous data. They start the row index and end the first index.
Now, we will bind data to the Repeater control, and perform the start and end row indexes of the merging examples.
In the sample code, the #27 to #31 rows are returned as follows:
(F + f. Data ++ f. StartRowIndex ++ f. EndRowIndex +); View Code
Now let's write the OnItemDataBound = "RepeaterFruit_ItemDataBound" event.
Lines #48 and #65 solve the code redundancy problem of the previous version.
#52 rows. If the starting row index is the same as the starting index of the rows in the Set, column merge is processed.
# There are no consecutive data in 54 rows, so you don't have to merge them.
#56 rows with columns that can be merged. Adding 1 to the end index of the row minus the start index of the row in the set is equal to the number of rows merged as the value of rowspan.
#61 rows. Once the column merging is completed, the previous loop exists.
It should be easy to understand.
Look at the final result: