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
 GridViewDeletedEventHandler, délégu...
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
GridViewDeletedEventHandler Delegate

Represents the method that handles the RowDeleted event of a GridView control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public Delegate Sub GridViewDeletedEventHandler ( _
    sender As Object, _
    e As GridViewDeletedEventArgs _
)
C#
public delegate void GridViewDeletedEventHandler(
    Object sender,
    GridViewDeletedEventArgs e
)
Visual C++
public delegate void GridViewDeletedEventHandler(
    Object^ sender, 
    GridViewDeletedEventArgs^ e
)
F#
type GridViewDeletedEventHandler = 
    delegate of 
        sender:Object * 
        e:GridViewDeletedEventArgs -> unit

Parameters

sender
Type: System..::.Object
The source of the event.
e
Type: System.Web.UI.WebControls..::.GridViewDeletedEventArgs
A GridViewDeletedEventArgs that contains the event data.

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.

When you create a GridViewDeletedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.

The following example demonstrates how to programmatically add a GridViewDeletedEventHandler delegate to the RowDeleted event of a GridView control.

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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Create a new GridView control.
    Dim customersGridView As New GridView()

    ' Set the GridView control's properties.
    customersGridView.ID = "CustomersGridView"
    customersGridView.DataSourceID = "CustomersSqlDataSource"
    customersGridView.AutoGenerateColumns = True
    customersGridView.AutoGenerateDeleteButton = True

    Dim keyArray() As String = {"CustomerID"}
    customersGridView.DataKeyNames = keyArray

    ' Programmatically register the event-handling method
    ' for the RowDeleted event of the GridView control.
    AddHandler customersGridView.RowDeleted, AddressOf CustomersGridView_RowDeleted

    ' Add the GridView control to the Controls collection
    ' of the PlaceHolder control.
    GridViewPlaceHolder.Controls.Add(customersGridView)

  End Sub

  Sub CustomersGridView_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs)

    ' Display whether the delete operation succeeded.
    If e.Exception Is Nothing Then

      Message.Text = "Row deleted successfully."

    Else

      Message.Text = "An error occurred while attempting to deleting the row."
      e.ExceptionHandled = True

    End If

  End Sub

</script>

<html  >
  <head runat="server">
    <title>GridViewDeletedEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridViewDeletedEventHandler Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <asp:placeholder id="GridViewPlaceHolder"
        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="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 Page_Load(Object sender, EventArgs e)
  {

    // Create a new GridView control.
    GridView customersGridView = new GridView();

    // Set the GridView control's properties.
    customersGridView.ID = "CustomersGridView";
    customersGridView.DataSourceID = "CustomersSqlDataSource";
    customersGridView.AutoGenerateColumns = true;
    customersGridView.AutoGenerateDeleteButton = true;
    customersGridView.DataKeyNames = new String[1] { "CustomerID" };

    // Programmatically register the event-handling method
    // for the RowDeleted event of the GridView control.
    customersGridView.RowDeleted += new GridViewDeletedEventHandler(this.CustomersGridView_RowDeleted);

    // Add the GridView control to the Controls collection
    // of the PlaceHolder control.
    GridViewPlaceHolder.Controls.Add(customersGridView);

  }

  void CustomersGridView_RowDeleted(Object sender, GridViewDeletedEventArgs e)
  {

    // Display whether the delete operation succeeded.
    if(e.Exception == null)
    {
      Message.Text = "Row deleted successfully.";
    }
    else
    {
      Message.Text = "An error occurred while attempting to deleting the row.";
      e.ExceptionHandled = true;   
    }

  }

</script>

<html  >
  <head runat="server">
    <title>GridViewDeletedEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridViewDeletedEventHandler Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <asp:placeholder id="GridViewPlaceHolder"
        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="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>

The following example demonstrates how to declaratively add a GridViewDeletedEventHandler delegate to the RowDeleted event of a GridView control.

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(sender As Object, e As GridViewDeletedEventArgs)

    ' Display whether the delete operation succeeded.
    If e.Exception Is Nothing Then

      Message.Text = "Row deleted successfully."

    Else

      Message.Text = "An error occurred while attempting to delete the row."
      e.ExceptionHandled = True

    End If

  End Sub

</script>

<html  >
  <head runat="server">
    <title>GridView RowDeleted Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView RowDeleted Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <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)
  {

    // Display whether the delete operation succeeded.
    if(e.Exception == null)
    {
      Message.Text = "Row deleted successfully.";
    }
    else
    {
      Message.Text = "An error occurred while attempting to delete the row.";
      e.ExceptionHandled = true;   
    }

  }

</script>

<html  >
  <head runat="server">
    <title>GridView RowDeleted Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView RowDeleted Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <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.
Bibliothèque de classes .NET Framework
GridViewDeletedEventHandler, délégué

Représente la méthode qui gère l'événement RowDeleted d'un contrôle GridView.

Espace de noms :  System.Web.UI.WebControls
Assembly :  System.Web (dans System.Web.dll)
Visual Basic
Public Delegate Sub GridViewDeletedEventHandler ( _
    sender As Object, _
    e As GridViewDeletedEventArgs _
)
C#
public delegate void GridViewDeletedEventHandler(
    Object sender,
    GridViewDeletedEventArgs e
)
VisualC++
public delegate void GridViewDeletedEventHandler(
    Object^ sender, 
    GridViewDeletedEventArgs^ e
)
F#
type GridViewDeletedEventHandler = 
    delegate of 
        sender:Object * 
        e:GridViewDeletedEventArgs -> unit

Paramètres

sender
Type : System..::.Object
Source de l'événement.
e
Type : System.Web.UI.WebControls..::.GridViewDeletedEventArgs
GridViewDeletedEventArgs qui contient les données d'événement.

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.

Lorsque vous créez un délégué GridViewDeletedEventHandler, vous spécifiez la méthode qui gérera l'événement. Pour associer l'événement à votre gestionnaire d'événements, ajoutez une instance du délégué à l'événement. Le gestionnaire d'événements est appelé chaque fois qu'un événement se produit, sauf si vous supprimez le délégué. Pour plus d'informations sur les délégués de gestionnaires d'événements, consultez Événements et délégués.

L'exemple suivant montre comment ajouter par programme un délégué GridViewDeletedEventHandler à l'événement RowDeleted d'un contrôle GridView.

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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Create a new GridView control.
    Dim customersGridView As New GridView()

    ' Set the GridView control's properties.
    customersGridView.ID = "CustomersGridView"
    customersGridView.DataSourceID = "CustomersSqlDataSource"
    customersGridView.AutoGenerateColumns = True
    customersGridView.AutoGenerateDeleteButton = True

    Dim keyArray() As String = {"CustomerID"}
    customersGridView.DataKeyNames = keyArray

    ' Programmatically register the event-handling method
    ' for the RowDeleted event of the GridView control.
    AddHandler customersGridView.RowDeleted, AddressOf CustomersGridView_RowDeleted

    ' Add the GridView control to the Controls collection
    ' of the PlaceHolder control.
    GridViewPlaceHolder.Controls.Add(customersGridView)

  End Sub

  Sub CustomersGridView_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs)

    ' Display whether the delete operation succeeded.
    If e.Exception Is Nothing Then

      Message.Text = "Row deleted successfully."

    Else

      Message.Text = "An error occurred while attempting to deleting the row."
      e.ExceptionHandled = True

    End If

  End Sub

</script>

<html  >
  <head runat="server">
    <title>GridViewDeletedEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridViewDeletedEventHandler Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <asp:placeholder id="GridViewPlaceHolder"
        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="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 Page_Load(Object sender, EventArgs e)
  {

    // Create a new GridView control.
    GridView customersGridView = new GridView();

    // Set the GridView control's properties.
    customersGridView.ID = "CustomersGridView";
    customersGridView.DataSourceID = "CustomersSqlDataSource";
    customersGridView.AutoGenerateColumns = true;
    customersGridView.AutoGenerateDeleteButton = true;
    customersGridView.DataKeyNames = new String[1] { "CustomerID" };

    // Programmatically register the event-handling method
    // for the RowDeleted event of the GridView control.
    customersGridView.RowDeleted += new GridViewDeletedEventHandler(this.CustomersGridView_RowDeleted);

    // Add the GridView control to the Controls collection
    // of the PlaceHolder control.
    GridViewPlaceHolder.Controls.Add(customersGridView);

  }

  void CustomersGridView_RowDeleted(Object sender, GridViewDeletedEventArgs e)
  {

    // Display whether the delete operation succeeded.
    if(e.Exception == null)
    {
      Message.Text = "Row deleted successfully.";
    }
    else
    {
      Message.Text = "An error occurred while attempting to deleting the row.";
      e.ExceptionHandled = true;   
    }

  }

</script>

<html  >
  <head runat="server">
    <title>GridViewDeletedEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridViewDeletedEventHandler Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <asp:placeholder id="GridViewPlaceHolder"
        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="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>

L'exemple suivant montre comment ajouter de façon déclarative un délégué GridViewDeletedEventHandler à l'événement RowDeleted d'un contrôle GridView.

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(sender As Object, e As GridViewDeletedEventArgs)

    ' Display whether the delete operation succeeded.
    If e.Exception Is Nothing Then

      Message.Text = "Row deleted successfully."

    Else

      Message.Text = "An error occurred while attempting to delete the row."
      e.ExceptionHandled = True

    End If

  End Sub

</script>

<html  >
  <head runat="server">
    <title>GridView RowDeleted Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView RowDeleted Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <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)
  {

    // Display whether the delete operation succeeded.
    if(e.Exception == null)
    {
      Message.Text = "Row deleted successfully.";
    }
    else
    {
      Message.Text = "An error occurred while attempting to delete the row.";
      e.ExceptionHandled = true;   
    }

  }

</script>

<html  >
  <head runat="server">
    <title>GridView RowDeleted Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView RowDeleted Example</h3>

      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>

      <br/>

      <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.
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