This documentation is archived and is not being maintained.

RepeaterItemCollection.CopyTo Method

Copies all the items from this RepeaterItemCollection to the specified System.Array object, starting at the specified index in the System.Array object.

[Visual Basic]
Public Overridable Sub CopyTo( _
   ByVal array As Array, _
   ByVal index As Integer _
) Implements ICollection.CopyTo
[C#]
public virtual void CopyTo(
 Array array,
 int index
);
[C++]
public: virtual void CopyTo(
 Array* array,
 int index
);
[JScript]
public function CopyTo(
   array : Array,
 index : int
);

Parameters

array
A zero-based System.Array object that receives the copied items from the RepeaterItemCollection.
index
The first position in the specified System.Array object to receive the copied contents.

Implements

ICollection.CopyTo

Remarks

Use this method to copy the contents of the RepeaterItemCollection into the specified System.Array object, starting at the specified index.

Note   The array parameter must be a zero-based System.Array object.

Example

[Visual Basic] 
<!-- 
To see this snippet in the context of a complete example,
see the RepeaterItemCollection class topic.
-->
    . . . 
         Sub CopyTo_Clicked(Sender As Object, e As EventArgs)
            labelDisplay.Text = "Invoking CopyTo method.<br>"
            labelDisplay.Text += "The Items collection contains: <br>"
            
            ' Display the elements of the RepeaterItemCollection using the CopyTo method.
            Dim myItemCollection As RepeaterItemCollection = myRepeater.Items
            Dim myItemArray(myItemCollection.Count-1) As RepeaterItem
            myItemCollection.CopyTo(myItemArray, 0)
            Dim index As Integer
            For index = 0 To myItemArray.Length - 1
               Dim myItem As RepeaterItem = CType(myItemArray.GetValue(index), RepeaterItem)
               labelDisplay.Text += CType(myItem.Controls(0), DataBoundLiteralControl).Text + "<br>"
            Next index
         End Sub 'CopyTo_Clicked

[C#] 
<!-- 
To see this snippet in the context of a complete example,
see the RepeaterItemCollection class topic.
-->
    . . . 
      void CopyTo_Clicked(Object Sender, EventArgs e)
      {
         labelDisplay.Text = "Invoking CopyTo method.<br>";
         labelDisplay.Text += "The Items collection contains: <br>";

         // Display the elements of the RepeaterItemCollection using the CopyTo method.
         RepeaterItemCollection  myItemCollection = myRepeater.Items;
         RepeaterItem[] myItemArray = new RepeaterItem[myItemCollection.Count];
         myItemCollection.CopyTo(myItemArray,0);
         for(int index=0;index < myItemArray.Length;index++)
         {
            RepeaterItem myItem = (RepeaterItem)myItemArray.GetValue(index);
            labelDisplay.Text += ((DataBoundLiteralControl)
               myItem.Controls[0]).Text + "<br>";
         }
      }

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

RepeaterItemCollection Class | RepeaterItemCollection Members | System.Web.UI.WebControls Namespace | System.Array

Show: