ListViewDeletedEventArgs ListViewDeletedEventArgs ListViewDeletedEventArgs ListViewDeletedEventArgs Class

Definition

Stellt Daten für das ItemDeleted-Ereignis bereit.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
Vererbung
ListViewDeletedEventArgsListViewDeletedEventArgsListViewDeletedEventArgsListViewDeletedEventArgs

Beispiele

Im folgenden Beispiel wird gezeigt, wie das ListViewDeletedEventArgs -Objekt verwendet wird, um zu bestimmen, ob während eines Löschvorgangs eine Ausnahme aufgetreten ist.The following example shows how to use the ListViewDeletedEventArgs object to determine whether an exception occurred during a delete operation. Das ListViewDeletedEventArgs -Objekt wird an die Ereignis Behandlungsmethode für das ItemDeleted -Ereignis übermittelt.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>

Hinweise

Das ListView -Steuerelement ItemDeleted löst das-Ereignis aus, wenn auf eine Lösch Schaltfläche im-Steuerelement geklickt wird ListView oder die DeleteItem -Methode aufgerufen wird, nachdem das Element vom-Steuerelement gelöschtThe 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. (Eine DELETE-Schaltfläche ist eine CommandName Schaltfläche, deren-Eigenschaft auf "Delete" festgelegt ist.) Dies ermöglicht es Ihnen, eine Ereignis Behandlungsmethode bereitzustellen, die bei jedem Auftreten dieses Ereignisses eine benutzerdefinierte Routine ausführt, z. b. das Überprüfen der Ergebnisse eines Löschvorgangs.(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.

Ein ListViewDeletedEventArgs -Objekt wird an die Ereignis Behandlungsmethode übermittelt.A ListViewDeletedEventArgs object is passed to the event-handling method. Mit diesem Objekt können Sie die Anzahl der betroffenen Elemente und ggf. aufgetretenen Ausnahmen ermitteln.This object enables you to determine the number of items affected and any exceptions that might have occurred. Verwenden Sie die AffectedRows -Eigenschaft, um die Anzahl der Elemente zu ermitteln, die vom Löschvorgang betroffen sind.To determine the number of items that were affected by the delete operation, use the AffectedRows property. Verwenden Sie die Exception -Eigenschaft, um zu bestimmen, ob Ausnahmen aufgetreten sind.To determine whether any exceptions occurred, use the Exception property. Sie können angeben, ob die Ausnahme in der Ereignis Behandlungsmethode behandelt wurde, indem Sie die ExceptionHandled -Eigenschaft festlegen.You can indicate whether you have handled the exception in the event-handling method by setting the ExceptionHandled property.

Hinweis

Wenn während des Löschvorgangs eine Ausnahme auftritt und die ExceptionHandled -Eigenschaft auf falsefestgelegt ist ListView , löst das Steuerelement die Ausnahme erneut aus.If an exception occurs during the delete operation and the ExceptionHandled property is set to false, the ListView control re-throws the exception.

Um auf die Schlüsselfelder des gelöschten Elements zuzugreifen, verwenden Keys Sie die-Eigenschaft.To access the key fields of the deleted item, use the Keys property. Um auf nicht Schlüsselfelder des gelöschten Elements zuzugreifen, verwenden Sie Values die-Eigenschaft.To access non-key fields of the deleted item, use the Values property. Eine Liste der anfänglichen Eigenschaftenwerte für eine Instanz der ListViewDeletedEventArgs-Klasse finden Sie im ListViewDeletedEventArgs-Konstruktor.For a list of initial property values for an instance of the ListViewDeletedEventArgs class, see the ListViewDeletedEventArgs constructor.

Konstruktoren

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

Initialisiert eine neue Instanz der ListViewDeletedEventArgs-Klasse.Initializes a new instance of the ListViewDeletedEventArgs class.

Eigenschaften

AffectedRows AffectedRows AffectedRows AffectedRows

Ruft die Anzahl der vom Löschvorgang betroffenen Zeilen ab.Gets the number of rows that were affected by the delete operation.

Exception Exception Exception Exception

Ruft die Ausnahme ab, die ggf. während des Löschvorgangs ausgelöst wurde.Gets the exception, if any, that was raised during the delete operation.

ExceptionHandled ExceptionHandled ExceptionHandled ExceptionHandled

Ruft einen Wert ab, der angibt, ob während der Behandlung des Löschvorgangs im Ereignishandler eine Ausnahme ausgelöst wurde, oder legt diesen Wert fest.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

Ruft die Schlüssel für das gelöschte Element ab.Gets the key or keys for the deleted item.

Values Values Values Values

Ruft die Nicht-Schlüsselfeldwerte für das gelöschte Element ab.Gets the non-key field values for the deleted item.

Methoden

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

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

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

Fungiert als Standardhashfunktion.Serves as the default hash function.

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

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

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

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

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

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Gilt für:

Siehe auch