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

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

AffectedRows プロパティを使用して、削除操作の影響を受けた行の数を確認します。通常、このプロパティは、以下のような場合に正しい数のレコードが削除されたことを確認するために使用されます。

AffectedRows プロパティを使用して、削除操作中にレコードが削除されたことを確認する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub CustomersGridView_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs) ' 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 whether the ' record was deleted. Sometimes an error might occur that ' does not raise an exception, but prevents the delete ' operation from completing. If e.AffectedRows = 1 Then Message.Text = "Record deleted successfully." Else Message.Text = "An error occurred during the delete operation." End If Else ' Insert the code to handle the exception. Message.Text = "An error occurred during the delete operation." ' 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>GridViewDeletedEventArgs Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames property as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogeneratedeletebutton="true" datakeynames="CustomerID" onrowdeleted="CustomersGridView_RowDeleted" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete from Customers where CustomerID = @CustomerID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomersGridView_RowDeleted(Object sender, GridViewDeletedEventArgs 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 whether the // record was deleted. Sometimes an error might occur that // does not raise an exception, but prevents the delete // operation from completing. if (e.AffectedRows == 1) { Message.Text = "Record deleted successfully."; } else { Message.Text = "An error occurred during the delete operation."; } } else { // Insert the code to handle the exception. Message.Text = "An error occurred during the delete operation."; // Use the ExceptionHandled property to indicate that the // exception is already handled. e.ExceptionHandled = true; } } </script> <html> <body> <form runat="server"> <h3>GridViewDeletedEventArgs Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames property as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogeneratedeletebutton="true" datakeynames="CustomerID" onrowdeleted="CustomersGridView_RowDeleted" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete from Customers where CustomerID = @CustomerID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 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に収録されているすべての辞書からGridViewDeletedEventArgs.AffectedRows プロパティを検索する場合は、下記のリンクをクリックしてください。

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