Export (0) Print
Expand All

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.

  • Drag the Repeater control from the Toolbox panel to your page.

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

  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.

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

  2. Press the less than key (<) to open the code completion drop-down.

  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 in the MSDN library.

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

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

  • AlternatingItemTemplate   Contains 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 FooterTemplate   Contains the text and controls to render at the beginning and end of the list, respectively.

  • SeparatorTemplate   Contains 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.

Community Additions

ADD
Show:
© 2014 Microsoft