次の方法で共有


Repeater.CreateItem(Int32, ListItemType) メソッド

定義

RepeaterItem コントロール内の指定した位置に、指定した項目の型で Repeater オブジェクトを作成します。

protected:
 virtual System::Web::UI::WebControls::RepeaterItem ^ CreateItem(int itemIndex, System::Web::UI::WebControls::ListItemType itemType);
protected virtual System.Web.UI.WebControls.RepeaterItem CreateItem (int itemIndex, System.Web.UI.WebControls.ListItemType itemType);
abstract member CreateItem : int * System.Web.UI.WebControls.ListItemType -> System.Web.UI.WebControls.RepeaterItem
override this.CreateItem : int * System.Web.UI.WebControls.ListItemType -> System.Web.UI.WebControls.RepeaterItem
Protected Overridable Function CreateItem (itemIndex As Integer, itemType As ListItemType) As RepeaterItem

パラメーター

itemIndex
Int32

作成した項目を格納する Repeater コントロール内の指定位置。

itemType
ListItemType

作成する ListItemType 項目の指定した型を表す Repeater

戻り値

新しい RepeaterItem オブジェクト。

次のコード例では、カスタム サーバー コントロールの メソッドを CreateItem オーバーライドして、常に新しい RepeaterItem 対応するインデックスを返し、カスタム Repeater サーバー コントロールに型を指定する方法を示します。

<%@ 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"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <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.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>
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);
    }
  }
}
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

適用対象

こちらもご覧ください