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
)

Parameters

array
Type: System.Array

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

index
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.

System_CAPS_noteNote

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"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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;

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableRowCollection Example</title>
</head>
<body>

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

      <h3>HtmlTableRowCollection Example</h3>

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

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>

      <br /><br />

      <input type="button" 
             value="Display row contents in the table"
             onserverclick = "Button_Click" 
             runat="server"/>

      <br /><br />

      <span id="Span1"
            runat="server"/>

   </form>

</body>
</html>

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