DetailsViewUpdatedEventArgs Třída

Definice

Poskytuje data pro událost ItemUpdated.

public ref class DetailsViewUpdatedEventArgs : EventArgs
public class DetailsViewUpdatedEventArgs : EventArgs
type DetailsViewUpdatedEventArgs = class
    inherit EventArgs
Public Class DetailsViewUpdatedEventArgs
Inherits EventArgs
Dědičnost
DetailsViewUpdatedEventArgs

Příklady

Následující příklad kódu ukazuje, jak použít DetailsViewUpdatedEventArgs objekt předaný obslužné rutině události události k ItemUpdated určení, zda došlo k výjimce během operace aktualizace.


<%@ 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 CustomerDetailsView_ItemUpdated(Object sender, 
    DetailsViewUpdatedEventArgs e)
  {
    // Use the Exception property to determine whether an exception
    // occurred during the insert operation.
    if (e.Exception == null)
    {
      // Use the Values property to get the value entered by 
      // the user for the CompanyName field.
      String keyFieldValue = e.Keys["CustomerID"].ToString();

      // Display a confirmation message.
      MessageLabel.Text = "Record " + keyFieldValue + 
        " updated successfully. ";

      // Display the old and new values.
      DisplayValues(e);

      if (e.AffectedRows == 1)
      {
        MessageLabel.Text += e.AffectedRows.ToString() + 
          " record updated.";
      }
      else
      {
        MessageLabel.Text += e.AffectedRows.ToString() + 
          " records updated.";
      }
    }
    else
    {
      // Insert the code to handle the exception.
      MessageLabel.Text = e.Exception.Message;

      // Use the ExceptionHandled property to indicate that the 
      // exception is already handled.
      e.ExceptionHandled = true;

      // When an exception occurs, keep the DetailsView
      // control in edit mode.
      e.KeepInEditMode = true;
    }
  }

  void DisplayValues(DetailsViewUpdatedEventArgs e)
  {
    
    MessageLabel.Text += "<br/></br>";
    
    // Iterate through the OldValue and NewValues
    // properties and display the values.
    for (int i = 0; i < e.OldValues.Count; i++)
    {
      MessageLabel.Text += "Old Value=" + e.OldValues[i].ToString() +
        ", New Value=" + e.NewValues[i].ToString() + "<br/>";
    }

    MessageLabel.Text += "</br>";
    
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DetailsViewUpdatedEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewUpdatedEventArgs Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          autogenerateeditbutton="true"  
          allowpaging="true"
          datakeynames="CustomerID" 
          onitemupdated="CustomerDetailsView_ItemUpdated"
          runat="server">
            
          <pagersettings position="Bottom"/> 
                    
        </asp:detailsview>
        
        <br/>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          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="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID"
          connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </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 CustomerDetailsView_ItemUpdated(ByVal sender As Object, ByVal e As DetailsViewUpdatedEventArgs)
  
    ' Use the Exception property to determine whether an exception
    ' occurred during the insert operation.
    If e.Exception Is Nothing Then
    
      ' Use the Values property to get the value entered by 
      ' the user for the CompanyName field.
      Dim keyFieldValue As String = e.Keys("CustomerID").ToString()

      ' Display a confirmation message.
      MessageLabel.Text = "Record " & keyFieldValue & _
        " updated successfully. "

      ' Display the old and new values.
      DisplayValues(e)

      If e.AffectedRows = 1 Then

        MessageLabel.Text &= e.AffectedRows.ToString() & _
          " record updated."
      
      Else
      
        MessageLabel.Text &= e.AffectedRows.ToString() & _
          " records updated."
      
      End If
    
    Else
    
      ' Insert the code to handle the exception.
      MessageLabel.Text = e.Exception.Message

      ' Use the ExceptionHandled property to indicate that the 
      ' exception is already handled.
      e.ExceptionHandled = True

      ' When an exception occurs, keep the DetailsView
      ' control in edit mode.
      e.KeepInEditMode = True
    
    End If
    
  End Sub

  Sub DisplayValues(ByVal e As DetailsViewUpdatedEventArgs)
    
    MessageLabel.Text &= "<br/></br>"
    
    ' Iterate through the OldValue and NewValues
    ' properties and display the values.
    Dim i As Integer
        
    For i = 0 To e.OldValues.Count - 1
    
      MessageLabel.Text &= "Old Value=" & e.OldValues(i).ToString() & _
        ", New Value=" & e.NewValues(i).ToString() & "<br/>"
    
    Next

    MessageLabel.Text &= "</br>"
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DetailsViewUpdatedEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewUpdatedEventArgs Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          autogenerateeditbutton="true"  
          allowpaging="true"
          datakeynames="CustomerID" 
          onitemupdated="CustomerDetailsView_ItemUpdated"
          runat="server">
            
          <pagersettings position="Bottom"/> 
                    
        </asp:detailsview>
        
        <br/>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          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="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID"
          connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>

Poznámky

Ovládací DetailsView prvek vyvolá ItemUpdated událost při kliknutí na tlačítko Aktualizovat (tlačítko s jeho CommandName vlastností nastavenou na "Aktualizovat") v rámci ovládacího prvku, ale poté DetailsView , co ovládací prvek aktualizuje záznam. To vám umožní poskytnout obslužnou rutinu události, která provádí vlastní rutinu, například kontrolu výsledků operace aktualizace, kdykoli dojde k této události.

DetailsViewUpdatedEventArgs Objekt je předán obslužné rutině události, což vám umožní určit počet ovlivněných záznamů a všechny výjimky, ke kterým mohlo dojít. Pokud chcete zjistit počet záznamů ovlivněných operací aktualizace, použijte AffectedRows vlastnost . Exception Pomocí vlastnosti určete, jestli došlo k nějakým výjimkám. Můžete také určit, zda byla výjimka zpracována v obslužné rutině události nastavením ExceptionHandled vlastnosti. Pokud potřebujete získat přístup k hodnotám klíčových polí aktualizovaného záznamu Keys , použijte vlastnost . K původním a aktualizovaným hodnotám polí bez klíče lze přistupovat pomocí OldValues vlastností a NewValues .

Ve výchozím nastavení se DetailsView ovládací prvek vrátí do režimu určeného DefaultMode vlastností po operaci aktualizace. Pokud chcete ovládací prvek zachovat DetailsView v režimu úprav, nastavte KeepInEditMode vlastnost na true.

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

Seznam počátečních hodnot vlastností pro instanci DetailsViewUpdatedEventArgs třídy naleznete v konstruktoru DetailsViewUpdatedEventArgs .

Konstruktory

DetailsViewUpdatedEventArgs(Int32, Exception)

Inicializuje novou instanci DetailsViewUpdatedEventArgs třídy.

Vlastnosti

AffectedRows

Získá počet řádků ovlivněných operací aktualizace.

Exception

Získá výjimku (pokud existuje), která byla vyvolána během operace aktualizace.

ExceptionHandled

Získá nebo nastaví hodnotu označující, zda byla vyvolána výjimka, která byla vyvolána během operace aktualizace byla zpracována v obslužné rutině události.

KeepInEditMode

Získá nebo nastaví hodnotu určující, zda DetailsView má ovládací prvek zůstat v režimu úprav po operaci aktualizace.

Keys

Získá slovník, který obsahuje klíč pole název/hodnota páry pro aktualizovaný záznam.

NewValues

Získá slovník, který obsahuje nové páry název pole a hodnota pro aktualizovaný záznam.

OldValues

Získá slovník, který obsahuje původní dvojice název pole a hodnota pro aktualizovaný záznam.

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Viz také