Dynamically merge Repeater control data Columns

Source: Internet
Author: User

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:


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.