Repeater.CreateItem Method (Int32, ListItemType)


This API supports the product infrastructure and is not intended to be used directly from your code.

Creates a RepeaterItem object with the specified item type and location within the Repeater control.

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

protected virtual RepeaterItem CreateItem(
	int itemIndex,
	ListItemType itemType


Type: System.Int32

The specified location within the Repeater control to place the created item.

Type: System.Web.UI.WebControls.ListItemType

A ListItemType that represents the specified type of the Repeater item to create.

Return Value

Type: System.Web.UI.WebControls.RepeaterItem

The new RepeaterItem object.

The following code example demonstrates how to override the CreateItem method in a custom server control so that it always returns a new RepeaterItem and corresponding index and type in a custom Repeater server control.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
        <title>Custom Repeater - CreateItem - C# Example</title>
    <script language="C#" runat="server">
      void Page_Load(Object Sender, EventArgs e) 
        if (!IsPostBack) 
          ArrayList values = new ArrayList();
          values.Add(new PositionData("Microsoft", "Msft"));
          values.Add(new PositionData("Intel", "Intc"));
          values.Add(new PositionData("Dell", "Dell"));

          Repeater1.DataSource = values;

      public class PositionData 
        private string name;
        private string ticker;

        public PositionData(string name, string ticker) 
 = name;
          this.ticker = ticker;

        public string Name 
            return name;

        public string Ticker 
            return ticker;
        <form id="Form1" method="post" runat="server">
            <h3>Custom Repeater - CreateItem - C# Example</h3>

            <aspSample:CustomRepeaterCreateItem id="Repeater1" runat="server">
                <table border="1" cellpadding="4" cellspacing="0">
                  <td> <%# DataBinder.Eval(Container.DataItem, "Name") %></td>
                  <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %></td>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomRepeaterCreateItem : System.Web.UI.WebControls.Repeater
    protected override System.Web.UI.WebControls.RepeaterItem CreateItem(int itemIndex, System.Web.UI.WebControls.ListItemType itemType)
      // Return a new RepeaterItem with the corresponding item index and type.
      return new System.Web.UI.WebControls.RepeaterItem(itemIndex, itemType);

.NET Framework
Available since 1.1
Return to top