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

Dim instance As GridViewRowCollection Dim array As GridViewRow() Dim index As Integer instance.CopyTo(array, index)

このメソッドを使用して、指定した System.Array オブジェクトに GridViewRowCollection オブジェクトの項目をコピーします。コピー操作は、指定したインデックスから開始されます。System.Array オブジェクトは、コレクション内の項目にアクセスするために使用できます。
![]() |
---|
array パラメータには、インデックス番号が 0 から始まる System.Array オブジェクトを使用する必要があります。 |

CopyTo メソッドを使用して、配列にコレクションの項目をコピーする方法の例を次に示します。この配列が反復処理され、最初のセルの値がページに表示されます。
<%@ Page language="VB" %> <script runat="server"> Sub AuthorsGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.Footer Then Message.Text = "The authors are:<br>" ' Copy the items in the Rows collection into an array. Dim rowArray(AuthorsGridView.Rows.Count - 1) As GridViewRow AuthorsGridView.Rows.CopyTo(rowArray, 0) ' Iterate though the array and display the value in the ' first cell of the row. Dim row As GridViewRow For Each row In rowArray Message.Text &= row.Cells(0).Text & "<br>" Next End If End Sub </script> <html> <body> <form runat="server"> <h3>GridViewRowCollection CopyTo Example</h3> <table> <tr> <td> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" onrowcreated="AuthorsGridView_RowCreated" runat="server"> <columns> <asp:boundfield datafield="au_lname" headertext="Last Name"/> <asp:boundfield datafield="au_fname" headertext="First Name"/> </columns> </asp:gridview> </td> <td> <asp:label id="Message" forecolor="Red" runat="server"/> </td> </tr> </table> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_lname], [au_fname] FROM [authors] WHERE [state]='CA'" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void AuthorsGridView_RowCreated(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Footer) { Message.Text = "The authors are:<br>"; // Copy the items in the Rows collection into an array. GridViewRow[] rowArray = new GridViewRow[AuthorsGridView.Rows.Count]; AuthorsGridView.Rows.CopyTo(rowArray, 0); // Iterate though the array and display the value in the // first cell of the row. foreach(GridViewRow row in rowArray) { Message.Text += row.Cells[0].Text + "<br>"; } } } </script> <html> <body> <form runat="server"> <h3>GridViewRowCollection CopyTo Example</h3> <table> <tr> <td> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" onrowcreated="AuthorsGridView_RowCreated" runat="server"> <columns> <asp:boundfield datafield="au_lname" headertext="Last Name"/> <asp:boundfield datafield="au_fname" headertext="First Name"/> </columns> </asp:gridview> </td> <td> <asp:label id="Message" forecolor="Red" runat="server"/> </td> </tr> </table> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_lname], [au_fname] FROM [authors] WHERE [state]='CA'" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGridViewRowCollection.CopyTo メソッドを検索する場合は、下記のリンクをクリックしてください。

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