HtmlTableRowCollection.CopyTo メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As HtmlTableRowCollection Dim array As Array Dim index As Integer instance.CopyTo(array, index)

このメソッドを使用して、指定した System.Array オブジェクトに HtmlTableRowCollection コレクションの内容をコピーします。コピー操作は、配列内の指定したインデックス位置から始まります。
![]() |
---|

CopyTo メソッドを使用して、HtmlTableRowCollection コレクションと同じ内容を格納する配列を作成する方法を次のコード例に示します。その後、配列は反復処理され、コレクションの内容が表示されます。
<%@ Page Language="VB" AutoEventWireup="True" %> <script runat="server"> Sub Button_Click(ByVal sender As Object, ByVal 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> <html> <head> <title>HtmlTableRowCollection Example</title> </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 row contents in the table" onserverclick = "Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <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> <head> <title>HtmlTableRowCollection Example</title> </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 row contents in the table" onserverclick = "Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <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> <html> <head> <title>HtmlTableRowCollection Example</title> </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 row contents in the table" onserverclick = "Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- HtmlTableRowCollection.CopyTo メソッドのページへのリンク