Obtain the total number of data source records in OnItemDataBound of the Repeater control

Source: Internet
Author: User

Insus. NEt has written an article "Repeater control last record highlight". Its implementation is to first declare a page-level variable, and then in Data_Binding () method to obtain the total number of records of the data source.

The focus of this article is to change the Writing Method of the previous article. Instead of declaring a page-level variable, it is obtained directly in the OnItemDataBound event.
First read. aspx:



Go to. aspx. cs to write the code behind code:



The #35 lines of code in is to convert the sender object to the Repeater control.
#37 lines of code converts Rpt. DataSource to a DataTable object. Why should we convert it to a able object instead of a dataset of other types? The Repeater control is bound to a DataTable dataset in Data_Binding. Therefore, you must match the conversion result.

You still need to preview the 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.