Export (0) Print
Expand All

Repeater.CreateItem Method

This method supports the .NET Framework 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
)
protected RepeaterItem CreateItem (
	int itemIndex, 
	ListItemType itemType
)
protected function CreateItem (
	itemIndex : int, 
	itemType : ListItemType
) : RepeaterItem

Parameters

itemIndex

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

itemType

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

Return Value

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" %>
<HTML>
	<HEAD>
		<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;
          Repeater1.DataBind();
        }
      }

      public class PositionData 
      {
        private string name;
        private string ticker;

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

        public string Name 
        {
          get 
          {
            return name;
          }
        }

        public string Ticker 
        {
          get 
          {
            return ticker;
          }
        }
      }
    </script>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>Custom Repeater - CreateItem - C# Example</h3>
			
			<aspSample:CustomRepeaterCreateItem id="Repeater1" runat="server">
          <HeaderTemplate>
            <table border="1" cellpadding="4" cellspacing="0">
              <tr>
                <th>Company</th>
                <th>Symbol</th>
              </tr>
          </HeaderTemplate>
          <ItemTemplate>
            <tr>
              <td> <%# DataBinder.Eval(Container.DataItem, "Name") %></td>
              <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %></td>
            </tr>
          </ItemTemplate>
          <FooterTemplate>
            </table>
          </FooterTemplate>
      </aspSample:CustomRepeaterCreateItem>
		</form>
	</body>
</HTML>

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<HTML>
	<HEAD>
		<title>Custom Repeater - CreateItem - VJ# Example</title>
    <script language="VJ#" runat="server">
        void Page_Load(Object Sender, EventArgs e) 
        {
            if (!get_IsPostBack()) {
                ArrayList values = new ArrayList();
                values.Add(new PositionData("Microsoft", "Msft"));
                values.Add(new PositionData("Intel", "Intc"));
                values.Add(new PositionData("Dell", "Dell"));
                Repeater1.set_DataSource(values);
                Repeater1.DataBind();
            }
        } //Page_Load

        public class PositionData 
        {
            private String name;
            private String ticker;

            public PositionData(String name, String ticker) 
            {
                this.name = name;
                this.ticker = ticker;
            } //PositionData

            /** @property 
             */
            public String get_Name()
            {
                return name;
            } //get_Name

            /** @property 
             */
            public String get_Ticker()
            {
                return ticker;
            } //get_Ticker
        } //PositionData 
    </script>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>Custom Repeater - CreateItem - VJ# Example</h3>
			
			<aspSample:CustomRepeaterCreateItem id="Repeater1" runat="server">
          <HeaderTemplate>
            <table border="1" cellpadding="4" cellspacing="0">
              <tr>
                <th>Company</th>
                <th>Symbol</th>
              </tr>
          </HeaderTemplate>
          <ItemTemplate>
            <tr>
              <td> <%# DataBinder.Eval(Container.get_DataItem(), "Name") %></td>
              <td> <%# DataBinder.Eval(Container.get_DataItem(), "Ticker") %></td>
            </tr>
          </ItemTemplate>
          <FooterTemplate>
            </table>
          </FooterTemplate>
      </aspSample:CustomRepeaterCreateItem>
		</form>
	</body>
</HTML>

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);
    }
  }
}

package Samples.AspNet.JSL.Controls; 

public class CustomRepeaterCreateItem
    extends System.Web.UI.WebControls.Repeater
{
    protected 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);
    } //CreateItem
} //CustomRepeaterCreateItem

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.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft