The day before yesterday, Insus. NET implemented "dynamically merge columns of the GridView data row DataRow". Today, I will play with the Repeater control, which is also used to dynamically merge certain column spaces.
The Repeater control has the same high degree of integration as the GridView control. The more free and loose the control, the worse the control.
On the website, we create a webpage and pull the Repeater control to the webpage:
Go to. aspx. cs to bind data to the Repeater control, database tables, stored procedures, and connect to the database to obtain data, which is not provided here.
Browsing effect:
OK. We started to merge data columns. As mentioned in the blog post, the Repeater control and GridVeiw control are quite different, and there is no reference for the merge method. But one thing is the same, and the merged events are still carried out in ItemCreated.
Add the OnItemCreated = "RepeaterFruit_ItemCreated" event to the Repeater control, remove the html in the original ItemTemplate, and use the Literal control instead. That is, all data rows are dynamically generated in the background OnItemCreated = "RepeaterFruit_ItemCreated" event.
Go to. aspx. cs to define two page-level variables. Refer to Part #1 of the Code. The #2 part of the code block analyzes the merged columns from the data source. Each field that can be merged occupies several rows of data and is filled in the Dictionary <string, int> set.
The OnItemCreated event is written as follows:
#1. The code line indicates the number of rows that match the current data row merging column in the collection that can be merged.
#2 code block. If there is only one row, no merge action is required. The original data can generate one row.
#3 code block. If fields to be merged are generated for the first time, you must add the rowspan attribute to the merged columns and assign values to them.
#4. The code block is the same merged column and does not need to be generated dynamically.
Effect after running the program: