Name

Repeater

Synopsis

This class represents a special kind of data-bound list control that can contain repeating buttons, static text, and other controls. The Repeater control requires more work than a straightforward DataGrid or DataList control because it contains no built-in styles or layout. Instead, you must create templates for the Repeater using HTML and ASP.NET tags in the .aspx file. Each template is bracketed inside the appropriate template tag (like <ItemTemplate>). You do not set the corresponding System.Web.UI.ITemplate properties of this class directly.

Every Repeater control requires an ItemTemplate. Additionally, an AlternatingItemTemplate can be used to allow items to alternate between two styles. These two templates will be bound when you use the DataBind() method. The other templates, like HeaderTemplate, FooterTemplate, and SeparatorTemplate, will not. If the DataSource property is set but no data is returned, only the HeaderTemplate and FooterTemplate will be rendered. If the DataSource property is not set (it will be Nothing by default), the control is not rendered at all.

The Repeater control is unique because it allows you enter any HTML content in a template, and even split HTML tags across more than one template. To use a table in your Repeater control, you should include the begin table tag (<table>) in the HeaderTemplate and the end table tag (</table>) in the FooterTemplate. You can then use a single table row tag (<tr>) in the ItemTemplate and multiple ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.