HtmlTableCellCollection.CopyTo Method
Copies the items from the HtmlTableCellCollection to the specified System.Array, beginning with the specified index in the System.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 HtmlTableCellCollection.
- index
- The first index in the specified System.Array to receive the items.
Implements
Remarks
Use this method to copy the contents of the HtmlTableCellCollection into the specified System.Array, starting at the specified index of 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 HtmlTableCellCollection. The array is then iterated through to display the contents of the HtmlTableCellCollection.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Button_Click(sender As Object, e As EventArgs) Dim myCellArray(1) As HtmlTableCell Dim cell As HtmlTableCell ' Copy the collection to an array. Table1.Rows(0).Cells.CopyTo(myCellArray, 0) Span1.InnerText = "The copied items from the selected row are: " ' Iterate through the array and display its contents. For Each cell In myCellArray Span1.InnerText = Span1.InnerText & " " & cell.InnerText Next cell End Sub </script> </head> <body> <form runat="server"> <h3>HtmlTableCellCollection 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 first row." 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) { HtmlTableCell[] myCellArray = new HtmlTableCell[2]; // Copy the collection to an array. Table1.Rows[0].Cells.CopyTo(myCellArray, 0); Span1.InnerText = "The copied items from the selected row are: "; // Iterate through the array and display its contents. foreach (HtmlTableCell cell in myCellArray) { Span1.InnerText = Span1.InnerText + " " + cell.InnerText; } } </script> </head> <body> <form runat="server"> <h3>HtmlTableCellCollection 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 first row." 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 myCellArray : HtmlTableCell[] = new HtmlTableCell[2]; // Copy the collection to an array. Table1.Rows[0].Cells.CopyTo(myCellArray, 0); Span1.InnerText = "The copied items from the selected row are: "; // Iterate through the array and display its contents. for (var i : int in myCellArray) { Span1.InnerText = Span1.InnerText + " " + myCellArray[i].InnerText; } } </script> </head> <body> <form runat="server"> <h3>HtmlTableCellCollection 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 first row." 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
HtmlTableCellCollection Class | HtmlTableCellCollection Members | System.Web.UI.HtmlControls Namespace | System.Array