ObjectDataSource.DeleteMethod Propriété

Définition

Obtient ou définit le nom de la méthode ou de la fonction que le contrôle ObjectDataSource appelle pour supprimer des données.Gets or sets the name of the method or function that the ObjectDataSource control invokes to delete data.

public:
 property System::String ^ DeleteMethod { System::String ^ get(); void set(System::String ^ value); };
public string DeleteMethod { get; set; }
member this.DeleteMethod : string with get, set
Public Property DeleteMethod As String

Valeur de propriété

Chaîne qui représente le nom de la méthode ou de la fonction que ObjectDataSource utilise pour supprimer des données.A string that represents the name of the method or function that the ObjectDataSource uses to delete data. La valeur par défaut est une chaîne vide ("").The default is an empty string ("").

Exemples

Cette section contient deux exemples de code.This section contains two code examples. Le premier exemple de code montre comment utiliser un ObjectDataSource objet avec un objet métier et un GridView contrôle pour supprimer des données.The first code example demonstrates how to use an ObjectDataSource object with a business object and a GridView control to delete data. Le deuxième exemple de code montre EmployeeLogic la classe utilisée dans le premier exemple de code.The second code example shows the EmployeeLogic class that is used in the first code example.

L’exemple de code suivant montre comment utiliser un ObjectDataSource contrôle avec un objet métier et un GridView contrôle pour supprimer des données.The following code example demonstrates how to use an ObjectDataSource control with a business object and a GridView control to delete data. Au départ, GridView le contrôle affiche un ensemble de tous les employés, à l’aide de la méthode SelectMethod spécifiée par la propriété pour récupérer les EmployeeLogic données de l’objet.Initially, the GridView control displays a set of all employees, using the method that is specified by the SelectMethod property to retrieve the data from the EmployeeLogic object. Étant donné AutoGenerateDeleteButton que la propriété a truela valeur GridView , le contrôle affiche automatiquement un bouton supprimer .Because the AutoGenerateDeleteButton property is set to true, the GridView control automatically displays a Delete button.

Si vous cliquez sur le bouton supprimer , l’opération de suppression est effectuée à l’aide de la méthode DeleteMethod spécifiée par la propriété et de tous les paramètres DeleteParameters spécifiés dans la collection.If you click the Delete button, the delete operation is performed using the method that is specified by the DeleteMethod property and any parameters that are specified in the DeleteParameters collection. Dans cet exemple de code, certaines étapes de prétraitement et de suivi sont également effectuées.In this code example, some preprocessing and post-processing steps are also performed. Le NorthwindEmployeeDeleting délégué est appelé pour gérer l' Deleting événement avant l’exécution de l’opération, et NorthwindEmployeeDeleted le délégué est appelé pour gérer Deleted l’événement une fois l’opération terminée pour effectuer la gestion des exceptions.The NorthwindEmployeeDeleting delegate is called to handle the Deleting event before the operation is performed, and the NorthwindEmployeeDeleted delegate is called to handle the Deleted event after the operation has completed to perform exception handling. Dans cet exemple, si une NorthwindDataException exception est levée, elle est gérée NorthwindDataException par le délégué.In this example, if a NorthwindDataException is thrown, it is handled by the NorthwindDataException delegate.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Import namespace="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>

L’exemple de code suivant montre EmployeeLogic la classe utilisée dans l’exemple de code précédent.The following code example shows the EmployeeLogic class that is used in the preceding code example.

namespace Samples.AspNet.CS {

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
  //
  // EmployeeLogic is a stateless business object that encapsulates
  // the operations you can perform on a NorthwindEmployee object.
  //
  public class EmployeeLogic {

    // Returns a collection of NorthwindEmployee objects.
    public static ICollection GetAllEmployees () {
      ArrayList al = new ArrayList();

      // Use the SqlDataSource class to wrap the
      // ADO.NET code required to query the database.
      ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];

      SqlDataSource sds
        = new SqlDataSource(cts.ConnectionString,
                            "SELECT EmployeeID FROM Employees");
      try {
        IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);

        // Iterate through the Enumeration and create a
        // NorthwindEmployee object for each ID.
        IEnumerator enumerator = IDs.GetEnumerator();
        while (enumerator.MoveNext()) {
          // The IEnumerable contains DataRowView objects.
          DataRowView row = enumerator.Current as DataRowView;
          string id = row["EmployeeID"].ToString();
          NorthwindEmployee nwe = new NorthwindEmployee(id);
          // Add the NorthwindEmployee object to the collection.
          al.Add(nwe);
        }
      }
      finally {
        // If anything strange happens, clean up.
        sds.Dispose();
      }

      return al;
    }

    public static NorthwindEmployee GetEmployee(object anID) {
      return new NorthwindEmployee(anID);
    }

    public static void DeleteEmployee(NorthwindEmployee ne) {
      bool retval = ne.Delete();
      if (! retval) { throw new NorthwindDataException("Employee delete failed."); }
      // Delete the object in memory.
      ne = null;
    }

    public static void DeleteEmployeeByID(int anID) {
        NorthwindEmployee tempEmp = new NorthwindEmployee(anID);
        DeleteEmployee(tempEmp);
    }
  }

  public class NorthwindEmployee {

    public NorthwindEmployee () {
      ID = DBNull.Value;
      lastName = "";
      firstName = "";
    }

    public NorthwindEmployee (object anID) {
      this.ID = anID;

      ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];

      SqlConnection conn = new SqlConnection (cts.ConnectionString);
      SqlCommand sc =
        new SqlCommand(" SELECT FirstName,LastName " +
                       " FROM Employees " +
                       " WHERE EmployeeID = @empId",
                       conn);
      // Add the employee ID parameter and set its value.
      sc.Parameters.Add(new SqlParameter("@empId",SqlDbType.Int)).Value = Int32.Parse(anID.ToString());
      SqlDataReader sdr = null;

      try {
        conn.Open();
        sdr = sc.ExecuteReader();

        // This is not a while loop. It only loops once.
        if (sdr != null && sdr.Read()) {
          // The IEnumerable contains DataRowView objects.
          this.firstName        = sdr["FirstName"].ToString();
          this.lastName         = sdr["LastName"].ToString();
        }
        else {
          throw new NorthwindDataException("Data not loaded for employee id.");
        }
      }
      finally {
        try {
          if (sdr != null) sdr.Close();
          conn.Close();
        }
        catch (SqlException) {
          // Log an event in the Application Event Log.
          throw;
        }
      }
    }

    private object ID;
    public object EmpID {
      get { return ID; }
    }

    private string lastName;
    public string LastName {
      get { return lastName; }
      set { lastName = value; }
    }

    private string firstName;
    public string FirstName {
      get { return firstName; }
      set { firstName = value;  }
    }
    public bool Delete () {
      if (ID.Equals(DBNull.Value)) {
        // The Employee object is not persisted.
        return true;
      }
      else {
        // The Employee object is persisted.
        // Use the SqlDataSource control as a convenient wrapper for
        // the ADO.NET code needed to delete a record from the database.
        ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];
        SqlDataSource sds = new SqlDataSource();

        try {
          sds.ConnectionString = cts.ConnectionString;
          sds.DeleteParameters.Add(new Parameter("empID", TypeCode.Int32, this.ID.ToString()));
          sds.DeleteCommand = "DELETE FROM [Order Details] " + 
              "WHERE OrderID IN (SELECT OrderID FROM Orders WHERE EmployeeID=@empID)";
          sds.Delete();
          sds.DeleteCommand = "DELETE FROM Orders WHERE EmployeeID=@empID";
          sds.Delete();
          sds.DeleteCommand = "DELETE FROM EmployeeTerritories WHERE EmployeeID=@empID";
          sds.Delete();
          sds.DeleteCommand = "DELETE FROM Employees WHERE EmployeeID=@empID";
          sds.Delete();
          return true;
        }
        finally {
          // Clean up resources.
          sds.Dispose();
        }
      }
    }
  }

  public class NorthwindDataException: Exception {
    public NorthwindDataException(string msg) : base (msg) { }
  }
}
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB
'
' EmployeeLogic is a stateless business object that encapsulates
' the operations you can perform on a NorthwindEmployee object.
Public Class EmployeeLogic

   ' Return a collection of NorthwindEmployee objects.
   Public Shared Function GetAllEmployees() As ICollection
      Dim al As New ArrayList()

      ' Use the SqlDataSource class to wrap the
      ' ADO.NET code required to query the database.
      Dim cts As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("NorthwindConnection")
      Dim sds As New SqlDataSource(cts.ConnectionString, _
                                  "SELECT EmployeeID FROM Employees")
      Try
         Dim IDs As IEnumerable = sds.Select(DataSourceSelectArguments.Empty)

         ' Iterate through the Enumeration and create a
         ' NorthwindEmployee object for each ID.
         Dim enumerator As IEnumerator = IDs.GetEnumerator()
         While enumerator.MoveNext()
            ' The IEnumerable contains DataRowView objects.
            Dim row As DataRowView = CType(enumerator.Current,DataRowView)
            Dim id As String = row("EmployeeID").ToString()
            Dim nwe As New NorthwindEmployee(id)
            ' Add the NorthwindEmployee object to the collection.
            al.Add(nwe)
         End While
      Finally
         ' If anything strange happens, clean up.
         sds.Dispose()
      End Try

      Return al
   End Function 'GetAllEmployees


   Public Shared Function GetEmployee(anID As Object) As NorthwindEmployee
      Return New NorthwindEmployee(anID)
   End Function 'GetEmployee


   Public Shared Sub DeleteEmployee(ne As NorthwindEmployee)
      Dim retval As Boolean = ne.Delete()
      If Not retval Then
         Throw New NorthwindDataException("Employee delete failed.")
      End If ' Delete the object in memory.
      ne = Nothing
   End Sub


   Public Shared Sub DeleteEmployeeByID(anID As Integer)
      Dim tempEmp As New NorthwindEmployee(anID)
      DeleteEmployee(tempEmp)
   End Sub

End Class

Public Class NorthwindEmployee

   Public Sub New()
      ID = DBNull.Value
      aLastName = ""
      aFirstName = ""
   End Sub


   Public Sub New(anID As Object)
      Me.ID = anID
      Dim cts As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("NorthwindConnection")
      Dim conn As New SqlConnection(cts.ConnectionString)
      Dim sc As New SqlCommand(" SELECT FirstName,LastName " & _
                               " FROM Employees " & _
                               " WHERE EmployeeID = @empId", conn)
      ' Add the employee ID parameter and set its value.
      sc.Parameters.Add(New SqlParameter("@empId", SqlDbType.Int)).Value = Int32.Parse(anID.ToString())
      Dim sdr As SqlDataReader = Nothing

      Try
         conn.Open()
         sdr = sc.ExecuteReader()

         ' This is not a while loop. It only loops once.
         If Not (sdr Is Nothing) AndAlso sdr.Read() Then
            ' The IEnumerable contains DataRowView objects.
            Me.aFirstName = sdr("FirstName").ToString()
            Me.aLastName = sdr("LastName").ToString()
         Else
            Throw New NorthwindDataException("Data not loaded for employee id.")
         End If
      Finally
         Try
            If Not (sdr Is Nothing) Then
               sdr.Close()
            End If
            conn.Close()
         Catch se As SqlException
            ' Log an event in the Application Event Log.
            Throw
         End Try
      End Try
   End Sub

   Private ID As Object
   Public ReadOnly Property EmpID() As Object
      Get
         Return ID
      End Get
   End Property

   Private aLastName As String
   Public Property LastName() As String
      Get
         Return aLastName
      End Get
      Set
         aLastName = value
      End Set
   End Property

   Private aFirstName As String
   Public Property FirstName() As String
      Get
         Return aFirstName
      End Get
      Set
         aFirstName = value
      End Set
   End Property

   Public Function Delete() As Boolean
      If ID.Equals(DBNull.Value) Then
         ' The Employee object is not persisted.
         Return True
      Else
         ' The Employee object is persisted.
         ' Use the SqlDataSource control as a convenient wrapper for
         ' the ADO.NET code needed to delete a record from the database.
         Dim cts As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("NorthwindConnection")
         Dim sds As New SqlDataSource()
         Try
            sds.ConnectionString = cts.ConnectionString
            sds.DeleteParameters.Add(New Parameter("empID", TypeCode.Int32, Me.ID.ToString()))
            sds.DeleteCommand = "DELETE FROM [Order Details] " & _
                "WHERE OrderID IN (SELECT OrderID FROM Orders WHERE EmployeeID=@empID)"
            sds.Delete()
            sds.DeleteCommand = "DELETE FROM Orders WHERE EmployeeID=@empID"
            sds.Delete()
            sds.DeleteCommand = "DELETE FROM EmployeeTerritories WHERE EmployeeID=@empID"
            sds.Delete()
            sds.DeleteCommand = "DELETE FROM Employees WHERE EmployeeID=@empID"
            sds.Delete()
            Return True
         Finally
            ' Clean up resources.
            sds.Dispose()
         End Try
      End If
   End Function 'Delete
End Class

Public Class NorthwindDataException
   Inherits Exception

   Public Sub New(msg As String)
      MyBase.New(msg)
   End Sub

End Class
End Namespace

Remarques

L’objet métier est supposé supprimer des données un enregistrement à la fois, plutôt que dans un lot.The business object is assumed to delete data one record at a time, rather than in a batch.

La DeleteMethod propriété délègue à DeleteMethod la propriété de ObjectDataSourceView l’objet associé au ObjectDataSource contrôle.The DeleteMethod property delegates to the DeleteMethod property of the ObjectDataSourceView object that is associated with the ObjectDataSource control.

Assurez-vous que les noms de paramètres ObjectDataSource configurés pour DeleteParameters le contrôle dans la collection correspondent aux noms de colonnes retournés par la méthode Select.Make sure that the parameter names configured for the ObjectDataSource control in the DeleteParameters collection match the column names that are returned by the select method.

Durée de vie des objetsObject Lifetime

La méthode identifiée par la DeleteMethod propriété peut être une méthode d’instance ou une static méthode (Shared dans Visual Basic).The method that is identified by the DeleteMethod property can be an instance method or a static (Shared in Visual Basic) method. S’il s’agit d’une méthode d’instance, l’objet métier est créé et détruit DeleteMethod chaque fois que la propriété est appelée.If it is an instance method, the business object is created and destroyed each time the DeleteMethod property is called. Vous pouvez gérer les ObjectCreated événements ObjectCreating et pour utiliser l’objet métier avant que la DeleteMethod propriété ne soit appelée.You can handle the ObjectCreated and ObjectCreating events to work with the business object before the DeleteMethod property is called. Vous pouvez également gérer l' ObjectDisposing événement déclenché après l’appel de DeleteMethod la propriété.You can also handle the ObjectDisposing event that is raised after the DeleteMethod property is called. Si l’objet métier implémente l' IDisposable interface, la Dispose méthode est appelée avant la destruction de l’objet.If the business object implements the IDisposable interface, the Dispose method is called before the object is destroyed. Si la méthode est une static méthodeShared (dans Visual Basic), l’objet métier n’est jamais créé et vous ne pouvez ObjectCreatedpas ObjectCreatinggérer les ObjectDisposing événements, et.If the method is a static (Shared in Visual Basic) method, the business object is never created and you cannot handle the ObjectCreated, ObjectCreating, and ObjectDisposing events.

Fusion de paramètresParameter Merging

Les paramètres sont ajoutés à DeleteParameters la collection à partir de trois sources:Parameters are added to the DeleteParameters collection from three sources:

  • À partir du contrôle lié aux données, au moment de l’exécution.From the data-bound control, at run time.

  • À partir DeleteParameters de l’élément, de manière déclarative.From the DeleteParameters element, declaratively.

  • À partir Deleting de la méthode, de manière déclarative.From the Deleting method, declaratively.

Tout d’abord, tous les paramètres générés à partir des contrôles liés aux données DeleteParameters sont ajoutés à la collection.First, any parameters that are generated from data-bound controls are added to the DeleteParameters collection. Par exemple, si le ObjectDataSource contrôle est lié à un GridView contrôle qui a les colonnes Name et Number, les paramètres Name pour Number et sont ajoutés à la collection.For example, if the ObjectDataSource control is bound to a GridView control that has the columns Name and Number, parameters for Name and Number are added to the collection. Le nom exact du paramètre dépend de la OldValuesParameterFormatString propriété.The exact name of the parameter depends on the OldValuesParameterFormatString property. Le type de données de ces paramètres stringest.The data type of these parameters is string. Ensuite, les paramètres qui sont répertoriés dans DeleteParameters l’élément sont ajoutés.Next, the parameters that are listed in the DeleteParameters element are added. Si un paramètre de l' DeleteParameters élément a le même nom qu’un paramètre qui figure déjà dans la DeleteParameters collection, le paramètre existant est modifié pour correspondre au paramètre spécifié dans l' DeleteParameters élément.If a parameter in the DeleteParameters element is found with the same name as a parameter that is already in the DeleteParameters collection, the existing parameter is modified to match the parameter that is specified in the DeleteParameters element. En général, il est utilisé pour modifier le type des données dans le paramètre.Typically, this is used to modify the type of the data in the parameter. Enfin, vous pouvez ajouter et supprimer par programmation des paramètres dans l' Deleting événement, qui se produit avant Delete l’exécution de la méthode.Finally, you can programmatically add and remove parameters in the Deleting event, which occurs before the Delete method is run. La méthode est résolue après la fusion des paramètres.The method is resolved after the parameters are merged. La résolution de méthode est décrite dans la section suivante.Method resolution is discussed in the next section.

Résolution de méthodeMethod Resolution

Lorsque la Delete méthode est appelée, les champs de données du contrôle lié aux données, les paramètres qui ont été créés de manière DeleteParameters déclarative dans l’élément et les paramètres qui ont été Deleting ajoutés dans le gestionnaire d’événements sont tous fusionnés.When the Delete method is called, the data fields from the data-bound control, the parameters that were created declaratively in the DeleteParameters element, and the parameters that were added in the Deleting event handler are all merged. (Pour plus d’informations, consultez la section précédente.) L' ObjectDataSource objet tente ensuite de trouver une méthode à appeler.(For more information, see the preceding section.) The ObjectDataSource object then attempts to find a method to call. Tout d’abord, il recherche une ou plusieurs méthodes portant le nom spécifié dans la DeleteMethod propriété.First, it looks for one or more methods with the name that is specified in the DeleteMethod property. Si aucune correspondance n’est trouvée, InvalidOperationException une exception est levée.If no match is found, an InvalidOperationException exception is thrown. Si une correspondance est trouvée, elle recherche des noms de paramètres correspondants.If a match is found, it then looks for matching parameter names. Par exemple, supposons que le type spécifié par la TypeName propriété possède deux méthodes nommées. DeleteARecordFor example, suppose the type that is specified by the TypeName property has two methods named DeleteARecord. L' DeleteARecord un a un paramètre ID,, et l' DeleteARecord autre a deux paramètres Name , Numberet.One DeleteARecord has one parameter, ID, and the other DeleteARecord has two parameters, Name and Number. Si la DeleteParameters collection n’a qu’un seul IDparamètre nommé DeleteARecord , la méthode avec ID uniquement le paramètre est appelée.If the DeleteParameters collection has only one parameter named ID, the DeleteARecord method with just the ID parameter is called. Le type du paramètre n’est pas vérifié pour la résolution des méthodes.The type of the parameter is not checked in resolving the methods. L’ordre des paramètres n’a pas d’importance.The order of the parameters does not matter.

Si la DataObjectTypeName propriété est définie, la méthode est résolue de manière différente.If the DataObjectTypeName property is set, the method is resolved in a different way. Recherche une méthode dont le nom est spécifié dans la DeleteMethod propriété qui accepte un paramètre du type spécifié dans la DataObjectTypeName propriété. ObjectDataSourceThe ObjectDataSource looks for a method with the name that is specified in the DeleteMethod property that takes one parameter of the type that is specified in the DataObjectTypeName property. Dans ce cas, le nom du paramètre n’a pas d’importance.In this case, the name of the parameter does not matter.

S’applique à

Voir aussi