Dynamically merge the Repeater control data column Ver2

Source: Internet
Author: User

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:


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.