Description and usage of the asp.net Repeater control

Source: Internet
Author: User

The Repeater control does not have a built-in rendering function, which means that you must provide a layout for the Repeater control by creating a template. When this page is running, the Repeater control presents one item for each record in turn through the records in the data source.

He is very simple. He is not powerful enough to use it. But as the old saying goes, what is the use of a knife? Can't we bite the chicken? In our daily applications, we often face this kind of choice. If we show that we can teach complex data, we can use the gridview, which is generally complicated to use DataList. What about simple data presentation? We use Repeater because it is simple, small, and most importantly flexible.

As we mentioned above, he does not have the built-in rendering function, so we need to use some templates to present his data. by the way, when it comes to presentation, I have a lot to talk about. He hasn't added the static item Function to you. In other words, he only deals with the database, and the average person doesn't talk to you.

The following table describes the templates supported by the Repeater control.
Template attributes
ItemTemplate
Contains HTML elements and controls that must be presented once for each data item in the data source.

AlternatingItemTemplate
Contains HTML elements and controls that must be presented once for each data item in the data source. Generally, you can use this template to create different appearances for alternate items. For example, you can specify a background color that is different from the color specified in ItemTemplate.

HeaderTemplate and FooterTemplate
The text and controls that are displayed at the beginning and end of the list.

SeparatorTemplate
Contains the elements rendered between each item. A typical example may be a straight line (using the hr element ).


We define the format in these templates. When the webpage is displayed, it will be pretty. Of course, if you are ugly, it cannot be beautiful.

In addition, the Item sample must be defined.
If the Repeater control does not specify a data source, it will not be displayed. If no data exists in the specified data source, the header and footer template will continue to be displayed.

The main points of this control are as follows:

1. Understand several templates of the control.
2. The Repeater control is simple and practical to read and present data.
3. Implement the set of the control
4. implement data paging (I posted a blog post that used to use the control pagination outside the repeater, but this time we put the pagination in the footer template, to make the control more beautiful)
5. Let our data entries become links. This is the only way to complete them.

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.