Main Page

  Previous Section Next Section


System.Web.UI.WebControls (system.web.dll)class

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 null by default), the control is not rendered at all.

The Repeater control is unique because it allows you to 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 table data tags (<td>).

The Repeater has no built-in support for item selection or editing. You can include a Button control inside an ItemTemplate, although you will have to write its tag manually, rather than using the Visual Studio .NET designer. When the user clicks this button, a ItemCommand event will be fired. This event provides additional information about the selected button and list item.

public class Repeater : System.Web.UI.Control, System.Web.UI.INamingContainer {
// Public Constructors
   public Repeater( );
// Public Instance Properties
   public virtual ITemplate AlternatingItemTemplate{set; get; }
   public override ControlCollection Controls{get; }             // overrides System.Web.UI.Control
   public virtual string DataMember{set; get; }
   public virtual object DataSource{set; get; }
   public virtual ITemplate FooterTemplate{set; get; }
   public virtual ITemplate HeaderTemplate{set; get; }
   public virtual RepeaterItemCollection Items{get; }
   public virtual ITemplate ItemTemplate{set; get; }
   public virtual ITemplate SeparatorTemplate{set; get; }
// Public Instance Methods
   public override void DataBind( );                 // overrides System.Web.UI.Control
// Protected Instance Methods
   protected override void CreateChildControls( );                // overrides System.Web.UI.Control
   protected virtual void CreateControlHierarchy(bool useDataSource);
   protected virtual RepeaterItem CreateItem(int itemIndex,         ListItemType itemType);
   protected virtual void InitializeItem(RepeaterItem item);
   protected override bool OnBubbleEvent(object sender, EventArgs e); // overrides System.Web.UI.Control
   protected override void OnDataBinding(EventArgs e);          // overrides System.Web.UI.Control
   protected virtual void OnItemCommand(RepeaterCommandEventArgs e);
   protected virtual void OnItemCreated(  RepeaterItemEventArgs e);
   protected virtual void OnItemDataBound(RepeaterItemEventArgs e);
// Events
   public event RepeaterCommandEventHandler ItemCommand;
   public event RepeaterItemEventHandler ItemCreated;
   public event RepeaterItemEventHandler ItemDataBound;


System.Object System.Web.UI.Control(System.ComponentModel.IComponent, System.IDisposable, System.Web.UI.IParserAccessor, System.Web.UI.IDataBindingsAccessor) Repeater(System.Web.UI.INamingContainer)

      Previous Section Next Section