Suggérer une traduction
 
Suggestions d'autres utilisateurs :

progress indicator
Aucune autre suggestion.
Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 4
Espaces de noms System.Web
System.Web.UI.WebControls
Réduire tout/Développer tout Réduire tout
Affichage du contenu :  côte à côteAffichage du contenu : côte à côte
.NET Framework Class Library
GridViewDeletedEventArgs Class

Provides data for the RowDeleted event.

System..::.Object
  System..::.EventArgs
    System.Web.UI.WebControls..::.GridViewDeletedEventArgs

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public Class GridViewDeletedEventArgs _
    Inherits EventArgs
C#
public class GridViewDeletedEventArgs : EventArgs
Visual C++
public ref class GridViewDeletedEventArgs : public EventArgs
F#
type GridViewDeletedEventArgs =  
    class
        inherit EventArgs
    end

The GridViewDeletedEventArgs type exposes the following members.

  NameDescription
Public methodGridViewDeletedEventArgsInitializes a new instance of the GridViewDeletedEventArgs class.
Top
  NameDescription
Public propertyAffectedRowsGets the number of rows affected by the delete operation.
Public propertyExceptionGets the exception (if any) that was raised during the delete operation.
Public propertyExceptionHandledGets or sets a value indicating whether an exception that was raised during the delete operation was handled in the event handler.
Public propertyKeysGets an ordered dictionary of key field name/value pairs for the deleted record.
Public propertyValuesGets a dictionary of the non-key field name/value pairs for the deleted record.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The GridView control raises the RowDeleted event when a Delete button (a button with its CommandName property set to "Delete") within the control is clicked, but after the GridView control deletes the record. This allows you to provide an event-handling method that performs a custom routine, such as checking the results of a delete operation, whenever this event occurs.

A GridViewDeletedEventArgs object is passed to the event-handling method, which allows you to determine the number of records affected and any exceptions that might have occurred. To determine the number of records affected by the delete operation, use the AffectedRows property. Use the Exception property to determine whether any exceptions occurred. You can also indicate whether the exception was handled in the event-handling method by setting the ExceptionHandled property.

NoteNote

If an exception occurs during the delete operation and the ExceptionHandled property is set to false, the GridView control re-throws the exception.

If you want to access the name/value pairs of the key fields and non-key fields of the deleted record, use the Keys and Values properties, respectively.

For more information about handling events, see Consuming Events.

The following example demonstrates how to use the GridViewDeletedEventArgs object passed to the event-handling method for the RowDeleted event to determine whether an exception occurred during a delete operation.

Visual Basic

<%@ 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">

  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  >
  <head runat="server">
    <title>GridViewDeletedEventArgs Example</title>
</head>
<body>
    <form id="form1" 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>

C#

<%@ 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">

  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  >
  <head runat="server">
    <title>GridViewDeletedEventArgs Example</title>
</head>
<body>
    <form id="form1" 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>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Bibliothèque de classes .NET Framework
GridViewDeletedEventArgs, classe

Fournit des données pour l'événement RowDeleted.

System..::.Object
  System..::.EventArgs
    System.Web.UI.WebControls..::.GridViewDeletedEventArgs

Espace de noms :  System.Web.UI.WebControls
Assembly :  System.Web (dans System.Web.dll)
Visual Basic
Public Class GridViewDeletedEventArgs _
    Inherits EventArgs
C#
public class GridViewDeletedEventArgs : EventArgs
VisualC++
public ref class GridViewDeletedEventArgs : public EventArgs
F#
type GridViewDeletedEventArgs =  
    class
        inherit EventArgs
    end

Le type GridViewDeletedEventArgs expose les membres suivants.

  NomDescription
Méthode publiqueGridViewDeletedEventArgsInitialise une nouvelle instance de la classe GridViewDeletedEventArgs.
Début
  NomDescription
Propriété publiqueAffectedRowsObtient le nombre de lignes affectées par l'opération de suppression.
Propriété publiqueExceptionObtient l'exception (s'il y en a une) qui a été levée pendant l'opération de suppression.
Propriété publiqueExceptionHandledObtient ou définit une valeur indiquant si une exception levée pendant l'opération de suppression a été gérée dans le gestionnaire d'événements.
Propriété publiqueKeysObtient un dictionnaire trié de paires nom/valeur de champ clé pour l'enregistrement supprimé.
Propriété publiqueValuesObtient un dictionnaire des paires nom/valeur de champ ne correspondant pas à une clé pour l'enregistrement supprimé.
Début
  NomDescription
Méthode publiqueEquals(Object)Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.)
Méthode protégéeFinalizeAutorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.)
Méthode publiqueGetHashCodeSert de fonction de hachage pour un type particulier. (Hérité de Object.)
Méthode publiqueGetTypeObtient le Type de l'instance actuelle. (Hérité de Object.)
Méthode protégéeMemberwiseCloneCrée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode publiqueToStringRetourne une chaîne qui représente l'objet actuel. (Hérité de Object.)
Début

Le contrôle GridView déclenche l'événement RowDeleted suite à un clic sur le bouton Supprimer (bouton dont la propriété CommandName a la valeur « Delete ») dans le contrôle, mais seulement après que le contrôle GridView a supprimé l'enregistrement. Cela vous permet de fournir une méthode de gestion d'événements qui exécute une routine personnalisée, par exemple la vérification des résultats d'une opération de suppression, lorsque cet événement se produit.

Un objet GridViewDeletedEventArgs est passé à la méthode de gestion d'événements qui vous permet de déterminer le nombre d'enregistrements affectés et toutes les exceptions éventuellement rencontrées. Pour déterminer le nombre d'enregistrements affectés par l'opération de suppression, utilisez la propriété AffectedRows. Utilisez la propriété Exception pour déterminer si des exceptions se sont produites. Vous pouvez également indiquer si l'exception a été gérée dans la méthode de gestion d'événements en définissant la propriété ExceptionHandled.

RemarqueRemarque

Si une exception se produit pendant l'opération de suppression et la propriété ExceptionHandled a la valeur false, le contrôle GridView lève de nouveau l'exception.

Si vous souhaitez accéder aux paires nom/valeur des champs clés et des champs ne correspondant pas à une clé de l'enregistrement supprimé, utilisez respectivement les propriétés Keys et Values.

Pour plus d'informations sur la gestion d'événements, consultez Consommation d'événements.

L'exemple suivant montre comment utiliser l'objet GridViewDeletedEventArgs passé à la méthode de gestion d'événements pour que l'événement RowDeleted détermine si une exception s'est produite pendant une opération de suppression.

Visual Basic

<%@ 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">

  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  >
  <head runat="server">
    <title>GridViewDeletedEventArgs Example</title>
</head>
<body>
    <form id="form1" 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>

C#

<%@ 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">

  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  >
  <head runat="server">
    <title>GridViewDeletedEventArgs Example</title>
</head>
<body>
    <form id="form1" 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>

.NET Framework

Pris en charge dans : 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2

Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2012 Microsoft. Tous droits réservés. Conditions d'utilisation | Marques | Confidentialité
Page view tracker