Export (0) Print
Expand All

Repeater Class

A data-bound list control that allows custom layout by repeating a specified template for each item displayed in the list.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Repeater : public Control, 
	INamingContainer
<asp:Repeater />

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 nullptr, 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 noteCaution:

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.

TopicLocation
How to: Create ASP.NET Web Control Templates DeclarativelyBuilding ASP .NET Web Applications
How to: Add a Repeater Control to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications
How To: Create ASP.NET Web Server Control Templates DynamicallyBuilding ASP .NET Web Applications
How to: Bind to Data in a Templated ControlBuilding ASP .NET Web Applications
How to: Respond to Button Events in DataList, Repeater, or GridView ItemsBuilding ASP .NET Web Applications
How to: Create ASP.NET Web Server Control TemplatesBuilding ASP .NET Web Applications
How to: Create ASP.NET Web Control Templates DeclarativelyBuilding ASP .NET Web Applications
How to: Add a Repeater Control to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications
How To: Create ASP.NET Web Server Control Templates DynamicallyBuilding ASP .NET Web Applications
How to: Bind to Data in a Templated ControlBuilding ASP .NET Web Applications
How to: Respond to Button Events in DataList, Repeater, or GridView ItemsBuilding ASP .NET Web Applications
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
How to: Create Web Server Control Templates Using the DesignerBuilding ASP .NET Web Applications in Visual Studio
How to: Add Repeater Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
How to: Bind to Data in a Templated Control in Visual StudioBuilding ASP .NET Web Applications in Visual Studio

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.

No code example is currently available or this language may not be supported.

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.

No code example is currently available or this language may not be supported.

System::Object
  System.Web.UI::Control
    System.Web.UI.WebControls::Repeater

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft