Highlight the last record of the Repeater control

Source: Internet
Author: User

Insus. NET has previously written "Repeater control first 10 records highlighted". However, there is an idea now that the last record is highlighted. How can this problem be achieved?

The technical requirement is to obtain the last index. You can subtract one record from the total record of the data source to obtain the index of the last Repeater control.

Create a Repeater control in the webpage and write the OnItemDataBound event.



Go to. aspx. cs to write the program:


#1 is to declare a total variable.

#2 is the DataTable of the data source to obtain the total number of records.
#3: determines whether the ItemIndex of the current Item is equal to one minus the total record. Why do we need to remove one? Because the index starts from 0. You do not need to subtract one from the total number, but add one to the Index, as shown below:


#4 is to get the ID set in Html --> "tr", and then add a style for its Attributes.


Webpage running effect:



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.