HtmlTableRowCollection.CopyTo Method
Copies the items from the HtmlTableRowCollection to the specified System.Array, starting at the specified index in the array.
[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 that receives the copied items from the HtmlTableRowCollection.
- index
- The first index in the specified array to receive the items.
Implements
Remarks
Use this method to copy the contents of the HtmlTableRowCollection into the specified System.Array, starting at the specified index in the array.
Note The array parameter must be a zero-based System.Array.
Example
[Visual Basic, C#, JScript] The following example demonstrates how to use the CopyTo method to create an array that contains the same contents as the HtmlTableRowCollection. The array is then iterated through to display the contents of the collection.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Button_Click(sender As Object, e As EventArgs) Dim myRowArray(1) As HtmlTableRow Dim row As HtmlTableRow ' 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. For Each row In myRowArray Span1.InnerText = Span1.InnerText & " " & row.Cells(0).InnerText & _ " " & row.Cells(1).InnerText Next row End Sub </script> </head> <body> <form runat="server"> <h3>HtmlTableRowCollection Example</h3> <table id="Table1" Border="1" BorderColor="black" runat="server"> <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 the contents of the rows in the table" OnServerClick = "Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <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> </head> <body> <form runat="server"> <h3>HtmlTableRowCollection Example</h3> <table id="Table1" Border="1" BorderColor="black" runat="server"> <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 the contents of the rows in the table" OnServerClick = "Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script runat="server"> function Button_Click(sender, e : EventArgs) { var myRowArray : HtmlTableRow[] = 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. for (var i : int = 0; i < 2; i ++ ) { Span1.InnerText = Span1.InnerText + " " + myRowArray[i].Cells[0].InnerText + " " + myRowArray[i].Cells[1].InnerText; } } </script> </head> <body> <form runat="server"> <h3>HtmlTableRowCollection Example</h3> <table id="Table1" Border="1" BorderColor="black" runat="server"> <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 the contents of the rows in the table" OnServerClick = "Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
HtmlTableRowCollection Class | HtmlTableRowCollection Members | System.Web.UI.HtmlControls Namespace | System.Array