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 Overridable Function CreateItem (
	itemIndex As Integer,
	itemType As ListItemType
) As RepeaterItem

Parameters

itemIndex
Type: System.Int32

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

itemType
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.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" 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 - VB.NET Example</title>
        <script language="VB" runat="server">
            Sub Page_Load(Sender As Object, e As EventArgs)
                If Not IsPostBack Then
                    Dim values As 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()
                End If
            End Sub

            Public Class PositionData

                Private myName As String
                Private myTicker As String        

                Public Sub New(newName As String, newTicker As String)
                    Me.myName = newName
                    Me.myTicker = newTicker
                End Sub        

                Public ReadOnly Property Name() As String
                    Get
                        Return myName
                    End Get
                End Property        

                Public ReadOnly Property Ticker() As String
                    Get
                        Return myTicker
                    End Get
                End Property
            End Class
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom Repeater - CreateItem - VB.NET 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>
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomRepeaterCreateItem
        Inherits System.Web.UI.WebControls.Repeater

        Protected Overrides Function CreateItem(ByVal itemIndex As Integer, ByVal itemType As System.Web.UI.WebControls.ListItemType) As System.Web.UI.WebControls.RepeaterItem

            ' Return a new RepeaterItem with the corresponding item index and type.
            Return New System.Web.UI.WebControls.RepeaterItem(itemIndex, itemType)
        End Function
    End Class
End Namespace

.NET Framework
Available since 1.1
Return to top
Show: