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

削除操作の影響を受けた行の数。


AffectedRows プロパティを使用して、削除操作の影響を受けたレコード数を確認する方法のコード例を次に示します。
<%@ Page language="VB" AutoEventWireup="False" %> <script runat="server"> Sub StoresDetailView_ItemDeleted(ByVal sender As Object, _ ByVal e As DetailsViewDeletedEventArgs) _ Handles CustomerDetailsView.ItemDeleted ' Use the Exception property to determine whether an exception ' occurred during the delete operation. If e.Exception Is Nothing Then ' Use the AffectedRows property to determine the numbers of ' rows affected by the delete operation. If e.AffectedRows = 1 Then MessageLabel.Text = e.AffectedRows.ToString() _ & " record deleted successfully." Else MessageLabel.Text = e.AffectedRows.ToString() _ & " records deleted successfully." End If Else ' Insert the code to handle the exception. MessageLabel.Text = e.Exception.Message ' Use the ExceptionHandled property to indicate that the ' exception is already handled. e.ExceptionHandled = True End If End Sub </script> <html> <body> <form runat="server"> <h3>DetailsViewDeletedEventArgs Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogeneratedeletebutton="true" autogeneraterows="true" allowpaging="true" 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 StoresDetailView_ItemDeleted(Object sender, DetailsViewDeletedEventArgs e) { // Use the Exception property to determine whether an exception // occurred during the delete operation. if (e.Exception == null) { // Use the AffectedRows property to determine the numbers of // rows affected by the delete operation. if (e.AffectedRows == 1) { MessageLabel.Text = e.AffectedRows.ToString() + " record deleted successfully."; } else { MessageLabel.Text = e.AffectedRows.ToString() + " records deleted successfully."; } } else { // Insert the code to handle the exception. MessageLabel.Text = e.Exception.Message; // Use the ExceptionHandled property to indicate that the // exception is already handled. e.ExceptionHandled = true; } } </script> <html> <body> <form runat="server"> <h3>DetailsViewDeletedEventArgs Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogeneratedeletebutton="true" autogeneraterows="true" allowpaging="true" onitemdeleted="StoresDetailView_ItemDeleted" 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DetailsViewDeletedEventArgs.AffectedRows プロパティのページへのリンク