RepeaterItemCollection 类

表示 Repeater 控件中的 RepeaterItem 对象的集合。无法继承此类。

**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)

语法

声明
Public NotInheritable Class RepeaterItemCollection
    Implements ICollection, IEnumerable
用法
Dim instance As RepeaterItemCollection
public sealed class RepeaterItemCollection : ICollection, IEnumerable
public ref class RepeaterItemCollection sealed : ICollection, IEnumerable
public final class RepeaterItemCollection implements ICollection, IEnumerable
public final class RepeaterItemCollection implements ICollection, IEnumerable

备注

RepeaterItemCollection 类表示 RepeaterItem 对象的集合,这些对象反过来表示 Repeater 控件中的数据项。若要以编程方式从 Repeater 控件中检索 RepeaterItem 对象,请使用下列方法之一:

  • 利用数组表示法使用索引器从集合中获取一个 RepeaterItem 对象。

  • 使用 CopyTo 方法将集合的内容复制到 System.Array 对象,然后可以使用该对象获取集合中的项。

  • 使用 GetEnumerator 方法创建一个 System.Collections.IEnumerator 接口,然后可使用该接口获取集合中的项。

  • 使用 foreach (C#) 或 For Each (Visual Basic) 循环访问集合。

Count 属性指定集合中项的总数,常用于确定集合的上限。

示例

Sub Page_Load(Sender As Object, e As EventArgs)
   If Not IsPostBack Then
      Dim myDataSource As New ArrayList()

      myDataSource.Add(New PositionData("Item 1", "$6.00"))
      myDataSource.Add(New PositionData("Item 2", "$7.48"))
      myDataSource.Add(New PositionData("Item 3", "$9.96"))

      ' Initialize the RepeaterItemCollection using the ArrayList as the data source.
      Dim myCollection As New RepeaterItemCollection(myDataSource)
      myRepeater.DataSource = myCollection
      myRepeater.DataBind()
   End If
End Sub 'Page_Load
void Page_Load(Object Sender, EventArgs e)
{
   if (!IsPostBack)
   {
      ArrayList myDataSource = new ArrayList();

      myDataSource.Add(new PositionData("Item 1", "$6.00"));
      myDataSource.Add(new PositionData("Item 2", "$7.48"));
      myDataSource.Add(new PositionData("Item 3", "$9.96"));
      
      // Initialize the RepeaterItemCollection using the ArrayList as the data source.
      RepeaterItemCollection myCollection = new RepeaterItemCollection(myDataSource);
      myRepeater.DataSource = myCollection;
      myRepeater.DataBind();
   }
}

继承层次结构

System.Object
  System.Web.UI.WebControls.RepeaterItemCollection

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

RepeaterItemCollection 成员
System.Web.UI.WebControls 命名空间
RepeaterItem 类
Repeater 类
Repeater.Items 属性
CopyTo
GetEnumerator
Count