Asp.net Repeater control description and detailed introduction and use method

  • 2020-03-31 20:34:27
  • OfStack

The Repeater control does not have built-in rendering capabilities, which means that the user must provide the layout for the Repeater control by creating a template. When the page runs, the Repeater control in turn renders an item for each record through the records in the data source.

He is simple and not powerful enough to use, but the old saying goes, how to kill a chicken with the ox, not with the ox what? Can't we kill the chicken? And we are often faced with this choice in everyday applications. Suppose we display and teach complex data, we can use gridview, and we can use DataList for more complex data. How about simple data rendering? We used it because it was simple, small and mostly flexible.

We said above that he doesn't have built-in rendering, so we'll have to use some templates to render his data. By the way, when it comes to presentation, I have a lot to say, he doesn't give you the ability to add static items, in other words, he only works with databases, he doesn't talk to you.

The following table describes the templates supported by the Repeater control.
Template attribute description
ItemTemplate
Contains HTML elements and controls to render once for each data item in the data source.

AlternatingItemTemplate
Contains HTML elements and controls to render once for each data item in the data source. Typically, you can use this template to create a different look for alternate items, such as specifying a background color that is different from the color specified in the ItemTemplate.

HeaderTemplate and FooterTemplate
Contains text and controls that are rendered at the beginning and end of the list, respectively.

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


We define the format in these templates so that when the page is rendered it will look pretty, but of course if you make it ugly, it won't look pretty.

In addition, the Item sample must be defined
If the Repeater control does not specify a data source, it will not display, and if there is no data in the specified data source, the header and foot templates will continue to display.

The main points we'll cover for this control are the following

1. Understand several templates for the control
2. Simple and practical Repeater control for data reading and rendering.
3, to achieve the use of the control of the set
4. Realize data paging (my previous blog post was to use control paging outside of repeater, but it always felt ugly, this time we put the page in the footer template, to make the control more beautiful)
5, let our data items become links, and only in this way, it is complete.

Related articles: