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.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public void CopyTo(
	Array array,
	int index


Type: System.Array

A zero-based System.Array that receives the copied items from the RepeaterItemCollection.

Type: System.Int32

The first position in the specified System.Array to receive the copied contents.


ICollection.CopyTo(Array, Int32)

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


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

To see this code 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];
for(int index=0;index < myItemArray.Length;index++)
   RepeaterItem myItem = (RepeaterItem)myItemArray.GetValue(index);
   labelDisplay.Text += ((DataBoundLiteralControl)
      myItem.Controls[0]).Text + "<br />";

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft