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

削除される行インデックス。

RowIndex プロパティを使用して、削除される行のインデックスを確認します。行インデックスは、行のプロパティにアクセスできるようにするために、指定された行を DetailsView コントロールの Rows コレクションから取得する場合によく使用されます。

RowIndex プロパティを使用して、削除される行のインデックスを確認する方法のコード例を次に示します。
<%@ Page language="VB" %> <script runat="server"> Sub CustomerDetailsView_ItemDeleting(ByVal sender As Object, _ ByVal e As DetailsViewDeleteEventArgs) ' Get customer ID and name from the Keys and Values ' properties. Dim keyValue As String = e.Keys("CustomerID").ToString() Dim customerName As String = e.Values("CompanyName").ToString() ' Cancel the delete operation if the user attempts to ' delete protected record. In this example, records ' with a customer ID that starts with with "A" cannot ' be deleted. If keyValue.StartsWith("A") Then e.Cancel = True MessageLabel.Text = "You cannot delete " & _ customerName & ". This customer is protected." Else MessageLabel.Text = "Row " & e.RowIndex.ToString() & _ " deleted." End If End Sub </script> <html> <body> <form runat="server"> <h3>DetailsViewDeleteEventArgs Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogeneratedeletebutton="true" autogeneraterows="true" allowpaging="true" onitemdeleting="CustomerDetailsView_ItemDeleting" runat="server"> <fieldheaderstyle backcolor="Navy" forecolor="White"/> </asp:detailsview> <asp:label id="MessageLabel" forecolor="Red" 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" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete [Customers] Where [CustomerID]=@CustomerID" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomerDetailsView_ItemDeleting(Object sender, DetailsViewDeleteEventArgs e) { // Get customer ID and name from the Keys and Values // properties. String keyValue = e.Keys["CustomerID"].ToString(); String customerName = e.Values["CompanyName"].ToString(); // Cancel the delete operation if the user attempts to // delete protected record. In this example, records // with a customer ID that starts with with "A" cannot // be deleted. if (keyValue.StartsWith("A")) { e.Cancel = true; MessageLabel.Text = "You cannot delete " + customerName + ". This customer is protected."; } else { MessageLabel.Text = "Row " + e.RowIndex.ToString() + " deleted."; } } </script> <html> <body> <form runat="server"> <h3>DetailsViewDeleteEventArgs Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogeneratedeletebutton="true" autogeneraterows="true" allowpaging="true" onitemdeleting="CustomerDetailsView_ItemDeleting" runat="server"> <fieldheaderstyle backcolor="Navy" forecolor="White"/> </asp:detailsview> <asp:label id="MessageLabel" forecolor="Red" 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" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete [Customers] Where [CustomerID]=@CustomerID" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DetailsViewDeleteEventArgs.RowIndex プロパティのページへのリンク