DetailsViewDeletedEventHandler デリゲート
アセンブリ: System.Web (system.web.dll 内)

Public Delegate Sub DetailsViewDeletedEventHandler ( _ sender As Object, _ e As DetailsViewDeletedEventArgs _ )
public delegate void DetailsViewDeletedEventHandler ( Object sender, DetailsViewDeletedEventArgs e )
public delegate void DetailsViewDeletedEventHandler ( Object^ sender, DetailsViewDeletedEventArgs^ e )
/** @delegate */ public delegate void DetailsViewDeletedEventHandler ( Object sender, DetailsViewDeletedEventArgs e )

DetailsView コントロールは、コントロール内の Delete ボタン (CommandName プロパティが "Delete" に設定されたボタン) がクリックされた場合に、DetailsView コントロールが実際にレコードを削除した後に ItemDeleted イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (削除操作の結果を確認するなど) を実行するイベント ハンドラを提供できます。
DetailsViewDeletedEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「イベントとデリゲート」を参照してください。

DetailsViewDeletedEventHandler デリゲートを、プログラムによって DetailsView コントロールの ItemDeleted イベントに追加する方法のコード例を次に示します。
<%@ page language="VB"%> <html> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create a new DetailsView object. Dim customerDetailsView As New DetailsView() ' Set the DetailsView object's properties. customerDetailsView.ID = "CustomerDetailsView" customerDetailsView.DataSourceID = "DetailsViewSource" customerDetailsView.AutoGenerateRows = True customerDetailsView.AutoGenerateDeleteButton = True customerDetailsView.AllowPaging = True customerDetailsView.PagerSettings.Mode = _ PagerButtons.NextPrevious Dim keyArray() As String = {"CustomerID"} customerDetailsView.DataKeyNames = keyArray ' Programmatically register the event-handling method ' for the ItemDeleted event of a DetailsView control. AddHandler customerDetailsView.ItemDeleted, _ AddressOf CustomerDetailView_ItemDeleted ' Add the DetailsView object to the Controls collection ' of the PlaceHolder control. DetailsViewPlaceHolder.Controls.Add(customerDetailsView) End Sub Sub CustomerDetailView_ItemDeleted(ByVal sender As Object, _ ByVal e As DetailsViewDeletedEventArgs) ' 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> <body> <form runat="server"> <h3>DetailsViewDeletedEventHandler Example</h3> <!-- Use a PlaceHolder control as the container for the --> <!-- dynamically generated DetailsView control. --> <asp:PlaceHolder id="DetailsViewPlaceHolder" runat="server"/> <br/><br/> <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#"%> <html> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Create a new DetailsView object. DetailsView customerDetailsView = new DetailsView(); // Set the DetailsView object's properties. customerDetailsView.ID = "CustomerDetailsView"; customerDetailsView.DataSourceID = "DetailsViewSource"; customerDetailsView.AutoGenerateRows = true; customerDetailsView.AutoGenerateDeleteButton = true; customerDetailsView.AllowPaging = true; customerDetailsView.PagerSettings.Mode = PagerButtons.NextPrevious; customerDetailsView.DataKeyNames = new String[1] { "CustomerID" }; // Programmatically register the event-handling method // for the ItemDeleted event of a DetailsView control. customerDetailsView.ItemDeleted += new DetailsViewDeletedEventHandler( this.CustomerDetailView_ItemDeleted); // Add the DetailsView object to the Controls collection // of the PlaceHolder control. DetailsViewPlaceHolder.Controls.Add(customerDetailsView); } void CustomerDetailView_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> <body> <form runat="server"> <h3>DetailsViewDeletedEventHandler Example</h3> <!-- Use a PlaceHolder control as the container for the --> <!-- dynamically generated DetailsView control. --> <asp:PlaceHolder id="DetailsViewPlaceHolder" runat="server"/> <br/><br/> <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>
DetailsViewDeletedEventHandler デリゲートを、宣言によって DetailsView コントロールの ItemDeleted イベントに追加する方法のコード例を次に示します。
<%@ page language="VB"%> <html> <script runat="server"> Sub CustomerDetailView_ItemDeleted(ByVal sender As Object, _ ByVal e As DetailsViewDeletedEventArgs) ' 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> <body> <form runat="server"> <h3>DetailsViewDeletedEventHandler Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" autogeneraterows="true" autogeneratedeletebutton="true" allowpaging="true" datakeynames="CustomerID" runat="server"> <pagersettings mode="NextPrevious"/> </asp:detailsview> <br/><br/> <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#"%> <html> <script runat="server"> void CustomerDetailView_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> <body> <form runat="server"> <h3>DetailsViewDeletedEventHandler Example</h3> <asp:detailsview id="CustomerDetailsView" datasourceid="DetailsViewSource" autogeneraterows="true" autogeneratedeletebutton="true" allowpaging="true" datakeynames="CustomerID" runat="server"> <pagersettings mode="NextPrevious"/> </asp:detailsview> <br/><br/> <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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DetailsViewDeletedEventHandler デリゲートのページへのリンク