Repeater Class
Assembly: System.Web (in system.web.dll)
The Repeater control is a basic templated data-bound list. It has no built-in layout or styles, so you must explicitly declare all layout, formatting, and style tags within the control's templates.
The Repeater control is the only Web control that allows you to split markup tags across the templates. To create a table using templates, include the begin table tag (<table>) in the HeaderTemplate, a single table row tag (<tr>) in the ItemTemplate, and the end table tag (</table>) in the FooterTemplate.
The Repeater control has no built-in selection capabilities or editing support. You can use the ItemCommand event to process control events that are raised from the templates to the control.
The Repeater control provides two properties to support data binding. To bind data to any object that implements the System.Collections.IEnumerable interface (such as a System.Data.DataView, a System.Collections.ArrayList, a System.Collections.Hashtable, or an array), or the IListSource interface, use the DataSource property to specify the data source. When you set the DataSource property, you must manually write the code to perform data binding. To automatically bind the Repeater control to a data source represented by a data source control, set the DataSourceID property to the ID of the data source control to use. When you set the DataSourceID property, the Repeater control automatically binds to the specified data source control on the first request. Therefore, you do not need to explicitly call the DataBind method unless you have changed data-related properties of the Repeater control.
A Repeater control binds its ItemTemplate and AlternatingItemTemplate to either the data model declared and referenced by its DataSource property or the data source control specified by its DataSourceID property. The HeaderTemplate, FooterTemplate, and SeparatorTemplate are not data-bound.
If the Repeater control's data source is set but no data is returned, the control renders the HeaderTemplate and FooterTemplate with no items. If the data source is a null reference (Nothing in Visual Basic), the Repeater is not rendered.
At a minimum, every Repeater control must define an ItemTemplate. However, other optional templates described in the following table can be used to customize the appearance of the list.
| Template name | Description |
|---|---|
| ItemTemplate | Defines the content and layout of items within the list. This template is required. |
| AlternatingItemTemplate | If defined, determines the content and layout of alternating (zero-based odd-indexed) items. If not defined, ItemTemplate is used. |
| SeparatorTemplate | If defined, is rendered between items (and alternating items). If not defined, a separator is not rendered. |
| HeaderTemplate | If defined, determines the content and layout of the list header. If not defined, a header is not rendered. |
| FooterTemplate | If defined, determines the content and layout of the list footer. If not defined, a footer is not rendered. |
Caution |
|---|
| This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input. For more information, see Validation Server Control Syntax. |
The following code example demonstrates how to use two simple Repeater controls on a page. The DataSource property is used to specify the data source for the Repeater control. The first Repeater displays its items in a table; the second Repeater displays its items in a comma-separated list.
The following code example demonstrates how to use the DataSourceID property to specify the data source for a Repeater control. The DataSourceID property is set to the ID property of the SqlDataSource control used to retrieve the data. When the page is loaded, the Repeater control automatically binds to the data source specified by the SqlDataSource control and the data is displayed to the user.
- AspNetHostingPermission to run the Repeater control in a hosted environment. Associated enumeration: AspNetHostingPermissionLevel.Minimal
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Caution