CopyTo Method
Collapse the table of content
Expand the table of content

HtmlTableRowCollection.CopyTo Method (Array, Int32)


Copies the items from the HtmlTableRowCollection collection to the specified System.Array object, starting at the specified index in the array.

Namespace:   System.Web.UI.HtmlControls
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 HtmlTableRowCollection.

Type: System.Int32

The first index in the specified array to receive the items.

Use this method to copy the contents of the HtmlTableRowCollection collection into the specified System.Array object, starting at the specified index in the array.


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

The following code example demonstrates how to use the CopyTo method to create an array that contains the same contents as the HtmlTableRowCollection collection. The array is then iterated through to display the contents of the collection.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void Button_Click(Object sender, EventArgs e)

    HtmlTableRow[] myRowArray = new HtmlTableRow[2];

    // Copy the collection to an array.
    Table1.Rows.CopyTo(myRowArray, 0);

    Span1.InnerText = "The copied items from the selected row are: ";

    // Iterate through the array and display its contents.
    foreach (HtmlTableRow row in myRowArray)

      Span1.InnerText = Span1.InnerText + " " + row.Cells[0].InnerText +
                        " " + row.Cells[1].InnerText;




<html xmlns="" >
   <title>HtmlTableRowCollection Example</title>

   <form id="form1" runat="server">

      <h3>HtmlTableRowCollection Example</h3>

       <table id="Table1" runat="server" 
       style="border-width: 1; border-color: Black">

               Cell 1
               Cell 2
               Cell 3
               Cell 4


      <br /><br />

      <input type="button" 
             value="Display row contents in the table"
             onserverclick = "Button_Click" 

      <br /><br />

      <span id="Span1"



.NET Framework
Available since 1.1
Return to top
© 2016 Microsoft