asp.net.ph

Skip Navigation Links

Introduction to the Repeater Control

Controls You Can Use on Web Forms   ASP.NET Data Controls   Repeater Control


The Repeater Web server control is a basic container control used for customizing the display of one or more records from a data source.

Like the DataList and the FormView controls, the Repeater does not specify a pre-defined layout for displaying the data. Authors must provide the user interface by using templates provided for the control.

When the page runs, the Repeater loops through the data source and renders the content for each record as a RepeaterItem object, the appearance of which is described in the template.

The following sections briefly introduce the main features of the Repeater control.

Binding Data to the Control

NOTE: The Repeater control must be bound to a data source; otherwise, the control will not render on the page.

The Repeater control provides the following options for binding to data:

  • Data binding using the DataSourceID property, which allows binding the Repeater control to a data source control. This is the recommended approach as it enables the Repeater control to take advantage of the capabilities of the data source control.
  • Data binding using the DataSource property, which allows binding to any data source that implements the ICollection or IEnumerable interface, including ADO.NET datasets and datareaders. This approach, though, requires coding.

When binding data, the Repeater displays one RepeaterItem for each record in the data source. You can, however, choose which fields in the data source to display for each item.

For general information about data binding in server controls, see Data Binding in Web Forms.

Templates for Control Layout

As mentioned, the Repeater does not have a built-in user interface. Using templates provided for the control, authors can define how the data associated with the control is to be presented. The following table lists the template types you can specify for the Repeater.

Template type Description
AlternatingItemTemplate Defines the content to render for every other data row. The AlternatingItemTemplate is typically used to specify a different appearance, such as a different background color, for the alternating rows in the data source.
FooterTemplate Defines the content for the footer row that is rendered at the bottom of the Repeater control. This template usually contains any additional content you would like to display in the footer row. The FooterTemplate cannot be data bound.
HeaderTemplate Defines the content for the header row that is rendered at the top of the Repeater control. This template usually contains any additional content you would like to display in the header row. The HeaderTemplate cannot be data bound.
ItemTemplate Defines the content to render for each data row.
SeparatorTemplate Defines the content to render between each data row. A typical use is to visually highlight the separation of items, for instance, by using an <hr> element. The SeparatorTemplate cannot be data bound.

At a minimum, the ItemTemplate must be defined.

NOTE: The ItemTemplate must contain at least one databinding expression that binds a control to a field from the data source; otherwise the Repeater has nothing to render.

For more information, see Web Server Controls Templates.

See Also

Adding Repeater Controls to a Web Forms Page



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note