GridView.RowDeleted Událost

Definice

Nastane, když na řádek kliknete na tlačítko Odstranit, ale poté, co GridView ovládací prvek odstraní řádek.

public:
 event System::Web::UI::WebControls::GridViewDeletedEventHandler ^ RowDeleted;
public event System.Web.UI.WebControls.GridViewDeletedEventHandler RowDeleted;
member this.RowDeleted : System.Web.UI.WebControls.GridViewDeletedEventHandler 
Public Custom Event RowDeleted As GridViewDeletedEventHandler 

Event Type

Příklady

Následující příklad ukazuje, jak použít RowDeleted událost ke kontrole výsledku operace odstranění. Zobrazí se zpráva, která uživateli oznámí, jestli operace proběhla úspěšně.


<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>

Poznámky

Událost RowDeleted se vyvolá po kliknutí na tlačítko Odstranit na řádku, ale poté, co GridView ovládací prvek řádek odstraní. To vám umožní poskytnout metodu zpracování událostí, která provádí vlastní rutinu, například kontrolu výsledků operace odstranění, kdykoli dojde k této události.

Objekt GridViewDeletedEventArgs je předán metodě zpracování událostí, která umožňuje určit počet ovlivněných řádků a případné výjimky. Můžete také určit, zda byla výjimka zpracována v metodě zpracování událostí nastavením ExceptionHandled vlastnosti objektu GridViewDeletedEventArgs .

Další informace o zpracování událostí najdete v tématu Zpracování a vyvolávání událostí.

Platí pro

Viz také