DetailsView.Rows プロパティ
アセンブリ: System.Web (system.web.dll 内)

DetailsView コントロール内のすべてのデータ行を格納する DetailsViewRowCollection。

Rows プロパティ (コレクション) は、DetailsView コントロールのデータ行を格納するために使用されます。DetailsView コントロールは、データ ソース内のレコードごとに DetailsViewRow オブジェクトを作成してから、そのオブジェクトをコレクションに追加することにより、Rows コレクションを自動的に作成します。一般的にこのプロパティは、コントロールの特定行にアクセスするため、または行のコレクション全体を反復処理するために使用されます。
![]() |
---|
Rows コレクションに格納されるのはデータ行だけです。ヘッダー行、フッター行、およびページ行を表す DetailsViewRow オブジェクトは、コレクションに含まれません。 |

Rows プロパティを使用して、DetailsView コントロールのデータ行にアクセスする方法のコード例を次に示します。データ行は、DetailsView コントロールからフィールド値を取得するために使用されます。
<%@ Page Language="VB" %> <script runat="server"> Sub CustomerDetailView_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs) ' Use the CommandName property to determine which button ' was clicked. If e.CommandName = "Add" Then ' Add the current store to the contact list. ' Get the row that contains the store name. In this ' example, the store name is in the second row (index 1) ' of the DetailsView control. Dim row As DetailsViewRow = CustomerDetailView.Rows(1) ' Get the store's name from the appropriate cell. ' In this example, the store name is in the second cell ' (index 1) of the row. Dim name As String = row.Cells(1).Text ' Create a ListItem object with the store's name. Dim item As New ListItem(name) ' Add the ListItem object to the ListBox, if the ' item doesn't already exist. If Not ContactListBox.Items.Contains(item) Then ContactListBox.Items.Add(item) End If End If End Sub </script> <html> <body> <form id="Form1" runat="server"> <h3> DetailsView ItemCommand Example</h3> <asp:DetailsView ID="CustomerDetailView" DataSourceID="DetailsViewSource" AutoGenerateRows="false" DataKeyNames="CustomerID" AllowPaging="true" OnItemCommand="CustomerDetailView_ItemCommand" runat="server"> <FieldHeaderStyle BackColor="Navy" ForeColor="White" /> <Fields> <asp:BoundField DataField="CustomerID" HeaderText="Store ID" /> <asp:BoundField DataField="CompanyName" HeaderText="Store Name" /> <asp:BoundField DataField="City" HeaderText="City" /> <asp:ButtonField CommandName="Add" Text="Add Contact" /> </Fields> </asp:DetailsView> <hr /> Contacts:<br /> <asp:ListBox ID="ContactListBox" runat="server" /> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the web.config file. --> <asp:SqlDataSource ID="DetailsViewSource" runat="server" ConnectionString= "<%$ ConnectionStrings:NorthWindConnectionString%>" InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)" SelectCommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"> </asp:SqlDataSource> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void CustomerDetailView_ItemCommand(Object sender, DetailsViewCommandEventArgs e) { // Use the CommandName property to determine which button // was clicked. if (e.CommandName == "Add") { // Add the current store to the contact list. // Get the row that contains the store name. In this // example, the store name is in the second row (index 1) // of the DetailsView control. DetailsViewRow row = CustomerDetailView.Rows[1]; // Get the store's name from the appropriate cell. // In this example, the store name is in the second cell // (index 1) of the row. String name = row.Cells[1].Text; // Create a ListItem object with the store's name. ListItem item = new ListItem(name); // Add the ListItem object to the ListBox, if the // item doesn't already exist. if (!ContactListBox.Items.Contains(item)) { ContactListBox.Items.Add(item); } } } </script> <html> <body> <form id="Form1" runat="server"> <h3> DetailsView ItemCommand Example</h3> <asp:DetailsView ID="CustomerDetailView" DataSourceID="DetailsViewSource" AutoGenerateRows="false" DataKeyNames="CustomerID" AllowPaging="true" OnItemCommand="CustomerDetailView_ItemCommand" runat="server"> <FieldHeaderStyle BackColor="Navy" ForeColor="White" /> <Fields> <asp:BoundField DataField="CustomerID" HeaderText="Store ID" /> <asp:BoundField DataField="CompanyName" HeaderText="Store Name" /> <asp:BoundField DataField="City" HeaderText="City" /> <asp:ButtonField CommandName="Add" Text="Add Contact" /> </Fields> </asp:DetailsView> <hr /> Contacts:<br /> <asp:ListBox ID="ContactListBox" runat="server" /> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the web.config file. --> <asp:SqlDataSource ID="DetailsViewSource" runat="server" ConnectionString= "<%$ ConnectionStrings:NorthWindConnectionString%>" InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)" SelectCommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"> </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に収録されているすべての辞書からDetailsView.Rows プロパティを検索する場合は、下記のリンクをクリックしてください。

- DetailsView.Rows プロパティのページへのリンク