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

Dim instance As ObjectDataSourceView Dim value As String value = instance.DeleteMethod instance.DeleteMethod = value
/** @property */ public String get_DeleteMethod () /** @property */ public void set_DeleteMethod (String value)
データを削除するために ObjectDataSourceView が使用するメソッドまたは関数の名前を表す文字列。既定値は空の文字列 ("") です。

DeleteMethod プロパティで指定するメソッドには、インスタンスのメソッド、つまり static (Visual Basic の場合は Shared) なメソッドを指定できます。インスタンス メソッドの場合は、DeleteMethod プロパティで指定するメソッドが呼び出されるたびにビジネス オブジェクトが作成され、破棄されます。ObjectCreated イベントを処理することで、DeleteMethod プロパティで指定したメソッドを呼び出す前にビジネス オブジェクトに対して作業を実行できます。DeleteMethod プロパティで指定されたメソッドが呼び出された後に発生する ObjectDisposing イベントを処理することもできます。メソッドが static (Visual Basic では Shared) なメソッドである場合は、ビジネス オブジェクトが作成されないので、これらのイベントを処理できません。
ObjectDataSource コントロールを扱うビジネス オブジェクトが複数のメソッドまたは関数を同じ名前で実装すると (メソッドのオーバーロード)、データ ソース コントロールは、DeleteParameters コレクションのパラメータなどの一連の条件に従って適切なものを呼び出そうとします。DeleteParameters コレクション内のパラメータが、DeleteMethod メソッド シグネチャのパラメータと一致しない場合、データ ソースは例外をスローします。

ビジネス オブジェクトおよび GridView コントロールで、ObjectDataSource コントロールを使用してデータを削除する方法を次のコード例に示します。GridView は、SelectMethod プロパティによって指定されたメソッドで EmployeeLogic オブジェクトからデータを取得し、最初に全従業員を表示します。AutoGenerateDeleteButton プロパティが true に設定されているため、GridView コントロールは自動的に削除ボタンを表示します。
[削除] ボタンをクリックすると、DeleteMethod プロパティで指定されたメソッド、および DeleteParameters コレクションで指定されたパラメータを使用して Delete 操作が実行されます。このコード例では、プリプロセスとポスト プロセスのステップも一部実行されます。Delete 操作の実行前に Deleting イベントを処理する場合は、NorthwindEmployeeDeleting デリゲートが呼び出されます。また、例外処理を実行するために、Delete 操作の完了後に発生する Deleted イベントを処理する場合は、NorthwindEmployeeDeleted デリゲートが呼び出されます。この例では、NorthwindDataException がスローされた場合、このデリゲートによって処理されます。
このコード例で使用されている EmployeeLogic 中間層ビジネス オブジェクトの実装を調べるには、ObjectDataSourceStatusEventArgs のトピックを参照してください。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %> <%@ Import namespace="Samples.AspNet.VB" %> <%@ Page language="vb" %> <Script runat="server"> ' Called before a Delete operation. Private Sub NorthwindEmployeeDeleting(ByVal source As Object, ByVal e As ObjectDataSourceMethodEventArgs) ' The GridView passes the ID of the employee ' to be deleted. However, the business object, EmployeeLogic , ' requires a NorthwindEmployee parameter, named "ne". Create ' it now and add it to the parameters collection. Dim paramsFromPage As IDictionary = e.InputParameters If Not paramsFromPage("EmpID") Is Nothing Then Dim ne As New NorthwindEmployee(paramsFromPage("EmpID").ToString()) ' Remove the old EmpID parameter. paramsFromPage.Clear() paramsFromPage.Add("ne", ne) End If End Sub ' NorthwindEmployeeDeleting ' Called after a Delete operation. Private Sub NorthwindEmployeeDeleted(ByVal source As Object, ByVal e As ObjectDataSourceStatusEventArgs) ' Handle the Exception if it is a NorthwindDataException. If Not e.Exception Is Nothing Then ' Handle the specific exception type. The ObjectDataSource wraps ' any Exceptions in a TargetInvokationException wrapper, so ' check the InnerException property for the expected Exception types. If e.Exception.InnerException.GetType().Equals(GetType(NorthwindDataException)) Then Label1.Text = e.Exception.InnerException.Message ' Because the exception is handled, there is ' no reason to throw it. e.ExceptionHandled = True End If End If End Sub ' NorthwindEmployeeDeleted </Script> <html> <head> <title>ObjectDataSource - VB Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:gridview id="GridView1" runat="server" datasourceid="ObjectDataSource1" autogeneratedeletebutton="true" autogeneratecolumns="false" datakeynames="EmpID"> <columns> <asp:boundfield headertext="EmpID" datafield="EmpID" /> <asp:boundfield headertext="First Name" datafield="FirstName" /> <asp:boundfield headertext="Last Name" datafield="LastName" /> </columns> </asp:gridview> <asp:objectdatasource id="ObjectDataSource1" runat="server" selectmethod="GetAllEmployees" deletemethod="DeleteEmployee" ondeleting="NorthwindEmployeeDeleting" ondeleted="NorthwindEmployeeDeleted" typename="Samples.AspNet.VB.EmployeeLogic"> <deleteparameters> <asp:parameter name="EmpID" type="Int32" /> </deleteparameters> </asp:objectdatasource> <asp:label id="Label1" runat="server" /> </form> </body> </html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %> <%@ Import namespace="Samples.AspNet.CS" %> <%@ Page language="c#" %> <Script runat="server"> private void NorthwindEmployeeDeleting(object source, ObjectDataSourceMethodEventArgs e) { // The GridView passes the ID of the employee // to be deleted. However, the buisiness object, EmployeeLogic, // requires a NorthwindEmployee parameter, named "ne". Create // it now and add it to the parameters collection. IDictionary paramsFromPage = e.InputParameters; if (paramsFromPage["EmpID"] != null) { NorthwindEmployee ne = new NorthwindEmployee( Int32.Parse(paramsFromPage["EmpID"].ToString())); // Remove the old EmpID parameter. paramsFromPage.Clear(); paramsFromPage.Add("ne", ne); } } private void NorthwindEmployeeDeleted(object source, ObjectDataSourceStatusEventArgs e) { // Handle the Exception if it is a NorthwindDataException if (e.Exception != null) { // Handle the specific exception type. The ObjectDataSource wraps // any Exceptions in a TargetInvokationException wrapper, so // check the InnerException property for expected Exception types. if (e.Exception.InnerException is NorthwindDataException) { Label1.Text = e.Exception.InnerException.Message; // Because the exception is handled, there is // no reason to throw it. e.ExceptionHandled = true; } } } </Script> <html> <head> <title>ObjectDataSource - C# Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:gridview id="GridView1" runat="server" datasourceid="ObjectDataSource1" autogeneratedeletebutton="true" autogeneratecolumns="false" datakeynames="EmpID"> <columns> <asp:boundfield headertext="EmpID" datafield="EmpID" /> <asp:boundfield headertext="First Name" datafield="FirstName" /> <asp:boundfield headertext="Last Name" datafield="LastName" /> </columns> </asp:gridview> <asp:objectdatasource id="ObjectDataSource1" runat="server" selectmethod="GetAllEmployees" deletemethod="DeleteEmployee" ondeleting="NorthwindEmployeeDeleting" ondeleted="NorthwindEmployeeDeleted" typename="Samples.AspNet.CS.EmployeeLogic"> <deleteparameters> <asp:parameter name="EmpID" type="Int32" /> </deleteparameters> </asp:objectdatasource> <asp:label id="Label1" 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ObjectDataSourceView.DeleteMethod プロパティのページへのリンク