Repeater control

The Repeater control is a container control that allows you to create custom lists out of any data that is available to the page. The Repeater control does not have a built-in rendering of its own, which means that you must provide the layout for the Repeater control by creating templates. When the page runs, the Repeater control loops through the records in the data source and renders an item for each record.

Because the Repeater control has no default look, you can use it to create many kinds of lists, including the following:

  • A table layout

  • A comma-delimited list (for example, a, b, c, d, and so on)

  • An XML formatted list

To add a Repeater control to a page

  • Drag the Repeater control from the Toolbox task pane to your page.

After you add a Repeater control, you can specify a data source for the control.

To bind the Repeater control to a data source

  1. In Design view, right-click the Repeater control, and then click Show Common Control Tasks.

  2. On the Common DropDownList Tasks menu, click Choose Data Source.

  3. In the Data Source Configuration Wizard, choose a source for the Repeater control. For more information, see Configure a data source by using a data bound control.

To use the Repeater control, you create templates that define the layout of the control's content. Templates can contain any combination of markup and controls. If no templates are defined, or if none of the templates contain elements, the control does not appear on the page when the application is run.

To add create templates for the Repeater control

  1. In Code view, place the insertion point inside the <asp:Repeater></asp:Repeater> tags.

  2. Press the less than (<) key to invoke the code completion dropdown.

  3. Click the template you want to create.

  4. Type the HTML you want for the template. For an example of template definitions, see How to: Add Repeater Web Server Controls to a Web Forms Page (Visual Studio) in the MSDN library.

The following list describes the Repeater templates that are supported by the Repeater control:

  • ItemTemplateContains the HTML elements and controls to render once for each data item in the data source.

  • AlternatingItemTemplateContains the HTML elements and controls to render once for every other data item in the data source. Typically, this template is used to create a different look for the alternating items, such as a different background color than the color that is specified in the ItemTemplate.

  • HeaderTemplate and FooterTemplateContains the text and controls to render at the beginning and end of the list, respectively.

  • SeparatorTemplateContains the elements to render between each item. A typical example might be a line (using an HR element).

For additional information about using the Repeater control, see Repeater Web Server Control Overview in the MSDN library.

See also

Concepts

ASP.NET overview

DataList control

DetailsView control

FormView control

GridView control