Repeater.CreateItem Method
.NET Framework 3.0
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.WebControlsAssembly: System.Web (in system.web.dll)
protected RepeaterItem CreateItem ( int itemIndex, ListItemType itemType )
protected function CreateItem ( itemIndex : int, itemType : ListItemType ) : RepeaterItem
Not applicable.
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.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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>
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
Community Additions
ADD
Show: