ListViewDeletedEventArgs ListViewDeletedEventArgs ListViewDeletedEventArgs ListViewDeletedEventArgs Class

Definizione

Fornisce dati per l'evento ItemDeleted.Provides data for the ItemDeleted event.

public ref class ListViewDeletedEventArgs : EventArgs
public class ListViewDeletedEventArgs : EventArgs
type ListViewDeletedEventArgs = class
    inherit EventArgs
Public Class ListViewDeletedEventArgs
Inherits EventArgs
Ereditarietà
ListViewDeletedEventArgsListViewDeletedEventArgsListViewDeletedEventArgsListViewDeletedEventArgs

Esempi

Nell'esempio seguente viene illustrato come utilizzare l' ListViewDeletedEventArgs oggetto per determinare se si è verificata un'eccezione durante un'operazione di eliminazione.The following example shows how to use the ListViewDeletedEventArgs object to determine whether an exception occurred during a delete operation. L' ListViewDeletedEventArgs oggetto viene passato al metodo di gestione degli eventi per l' ItemDeleted evento.The ListViewDeletedEventArgs object is passed to the event-handling method for the ItemDeleted event.

<%@ 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()
    {
        Message.Text = String.Empty;
    }
    
    void ContactsListView_ItemDeleted(Object sender, ListViewDeletedEventArgs e)
    {
        // Determine whether an exception occurred during the delete operation.
        if (e.Exception == null)
        {
            // Ensure that a record was deleted.
            if (e.AffectedRows > 0)
            {
                Message.Text = e.AffectedRows + " item(s) deleted successfully.";
            }
            else
            {
                Message.Text = "No item was deleted.";
            }
        }
        else
        {
            // Insert the code to handle the exception here.

            // Indicate that the exception has been handled.
            e.ExceptionHandled = true;
            Message.Text = "An error occurred during the delete operation.";
        }
    }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ListViewDeletedEventArgs Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListViewDeletedEventArgs Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>
            
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemDeleted="ContactsListView_ItemDeleted"  
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" runat="server" id="tblContacts" width="640px">
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td valign="top">
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
            <td>
              <asp:LinkButton ID="DeleteButton" runat="server" 
                CommandName="Delete" 
                Text="Delete" 
                OnClientClick="return confirm('Are you sure?');" />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects    -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET  -->
      <!-- expression to retrieve the connection string value     -->
      <!-- from the Web.config file.                              -->            
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] 
          FROM Person.Contact"
        DeleteCommand="DELETE FROM Person.Contact WHERE [ContactID] = @ContactID">
        <DeleteParameters>
            <asp:Parameter Name="ContactID" Type="Int32" />
        </DeleteParameters>
      </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 Page_Load()
        Message.Text = String.Empty
    End Sub
    
    Sub ContactsListView_ItemDeleted(sender As Object, e As ListViewDeletedEventArgs)

        ' Determine whether an exception occurred during the delete operation.
        If e.Exception Is Nothing Then
            ' Ensure that a record was deleted.
            If e.AffectedRows > 0 Then
                Message.Text = e.AffectedRows.ToString() & _
                    " item(s) deleted successfully."
            Else
                Message.Text = "No item was deleted."
            End If
        Else
            ' Insert the code to handle the exception here.

            ' Indicate that the exception has been handled.
            e.ExceptionHandled = true
            Message.Text = "An error occurred during the delete operation."
        End If
    End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListViewDeletedEventArgs Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListViewDeletedEventArgs Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>
            
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemDeleted="ContactsListView_ItemDeleted"  
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" runat="server" id="tblContacts" width="640px">
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td valign="top">
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
            <td>
              <asp:LinkButton ID="DeleteButton" runat="server" 
                CommandName="Delete" 
                Text="Delete" 
                OnClientClick="return confirm('Are you sure?');" />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects    -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET  -->
      <!-- expression to retrieve the connection string value     -->
      <!-- from the Web.config file.                              -->            
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] 
          FROM Person.Contact"
        DeleteCommand="DELETE FROM Person.Contact WHERE [ContactID] = @ContactID">
        <DeleteParameters>
            <asp:Parameter Name="ContactID" Type="Int32" />
        </DeleteParameters>
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

Commenti

Il ListView controllo genera l' ItemDeleted evento quando viene fatto clic su un pulsante Elimina nel controllo o viene DeleteItem chiamato il metodo, ma dopo che ListView il controllo ha eliminato l'elemento.The ListView control raises the ItemDeleted event when a Delete button in the control is clicked or the DeleteItem method is called, but after the ListView control deletes the item. Un pulsante Elimina è un pulsante la cui CommandName proprietà è impostata su "Delete". Questo consente di fornire un metodo di gestione degli eventi che esegue una routine personalizzata ogni volta che si verifica questo evento, ad esempio il controllo dei risultati di un'operazione di eliminazione.(A Delete button is a button whose CommandName property is set to "Delete".) This enables you to provide an event-handling method that performs a custom routine whenever this event occurs, such as checking the results of a delete operation.

Un ListViewDeletedEventArgs oggetto viene passato al metodo di gestione degli eventi.A ListViewDeletedEventArgs object is passed to the event-handling method. Questo oggetto consente di determinare il numero di elementi interessati e tutte le eccezioni che potrebbero essersi verificate.This object enables you to determine the number of items affected and any exceptions that might have occurred. Per determinare il numero di elementi interessati dall'operazione di eliminazione, utilizzare la AffectedRows proprietà.To determine the number of items that were affected by the delete operation, use the AffectedRows property. Per determinare se si sono verificate eccezioni, Exception utilizzare la proprietà.To determine whether any exceptions occurred, use the Exception property. È possibile indicare se l'eccezione è stata gestita nel metodo di gestione degli eventi impostando la ExceptionHandled proprietà.You can indicate whether you have handled the exception in the event-handling method by setting the ExceptionHandled property.

Nota

Se si verifica un'eccezione durante l'operazione di eliminazione ExceptionHandled e la proprietà è falseimpostata su ListView , il controllo genera nuovamente l'eccezione.If an exception occurs during the delete operation and the ExceptionHandled property is set to false, the ListView control re-throws the exception.

Per accedere ai campi chiave dell'elemento eliminato, utilizzare la Keys proprietà.To access the key fields of the deleted item, use the Keys property. Per accedere ai campi non chiave dell'elemento eliminato, utilizzare la Values proprietà.To access non-key fields of the deleted item, use the Values property. Per un elenco dei valori iniziali delle proprietà di un'istanza della classe ListViewDeletedEventArgs, vedere il costruttore ListViewDeletedEventArgs.For a list of initial property values for an instance of the ListViewDeletedEventArgs class, see the ListViewDeletedEventArgs constructor.

Costruttori

ListViewDeletedEventArgs(Int32, Exception) ListViewDeletedEventArgs(Int32, Exception) ListViewDeletedEventArgs(Int32, Exception) ListViewDeletedEventArgs(Int32, Exception)

Inizializza una nuova istanza della classe ListViewDeletedEventArgs.Initializes a new instance of the ListViewDeletedEventArgs class.

Proprietà

AffectedRows AffectedRows AffectedRows AffectedRows

Ottiene il numero di righe interessate dall'operazione di eliminazione.Gets the number of rows that were affected by the delete operation.

Exception Exception Exception Exception

Ottiene l'eventuale eccezione generata durante l'operazione di eliminazione.Gets the exception, if any, that was raised during the delete operation.

ExceptionHandled ExceptionHandled ExceptionHandled ExceptionHandled

Ottiene o imposta un valore che indica se un'eccezione generata durante l'operazione di eliminazione è stata gestita nel gestore eventi.Gets or sets a value that indicates whether an exception that was raised during the delete operation was handled in the event handler.

Keys Keys Keys Keys

Ottiene la chiave o le chiavi per l'elemento eliminato.Gets the key or keys for the deleted item.

Values Values Values Values

Ottiene i valori dei campi non chiave per l'elemento eliminato.Gets the non-key field values for the deleted item.

Metodi

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Inherited from Object)

Si applica a

Vedi anche