GridViewUpdateEventArgs.NewValues Eigenschaft

Definition

Ruft ein Wörterbuch ab, das die überarbeiteten Werte der Name-Wert-Paare von Nicht-Schlüsselfeldern für die zu aktualisierende Zeile enthält.Gets a dictionary containing the revised values of the non-key field name/value pairs in the row to update.

public:
 property System::Collections::Specialized::IOrderedDictionary ^ NewValues { System::Collections::Specialized::IOrderedDictionary ^ get(); };
public System.Collections.Specialized.IOrderedDictionary NewValues { get; }
member this.NewValues : System.Collections.Specialized.IOrderedDictionary
Public ReadOnly Property NewValues As IOrderedDictionary

Eigenschaftswert

Ein IOrderedDictionary-Objekt, das die überarbeiteten Werte der Name-Wert-Paare von Nicht-Schlüsselfeldern für die zu aktualisierende Zeile enthält.An IOrderedDictionary object containing the revised values of the non-key field name/value pairs in the row to update.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie die NewValues -Eigenschaft verwendet wird, um alle Werte, die vom Benutzer bereitgestellt werden, zu codieren, bevor die Datenquelle aktualisiert wird.The following example demonstrates how to use the NewValues property to HTML-encode all values supplied by the user before updating the data source.


<%@ 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_RowUpdating(Object sender, GridViewUpdateEventArgs e)
  {
     
    // Iterate through the NewValues collection and HTML encode all 
    // user-provided values before updating the data source.
    foreach (DictionaryEntry entry in e.NewValues)
    {
    
      e.NewValues[entry.Key] = Server.HtmlEncode(entry.Value.ToString());
    
    }
        
  }
       
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView RowUpdating Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView RowUpdating Example</h3>
            
      <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames property as read-only.    -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        allowpaging="true" 
        datakeynames="CustomerID"
        onrowupdating="CustomersGridView_RowUpdating"  
        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]"
        updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country 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_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    
    ' Use the CopyTo method to copy the DictionaryEntry objects in the 
    ' NewValues collection to an array.
    Dim records(e.NewValues.Count - 1) As DictionaryEntry
    e.NewValues.CopyTo(records, 0)
    
    ' Iterate through the array and HTML encode all user-provided values 
    ' before updating the data source.
    Dim entry As DictionaryEntry
    For Each entry In records
            
      e.NewValues(entry.Key) = Server.HtmlEncode(entry.Value.ToString())
      
    Next
        
  End Sub
       
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView RowUpdating Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView RowUpdating Example</h3>
            
      <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames property as read-only.    -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateeditbutton="true"
        allowpaging="true" 
        datakeynames="CustomerID"
        onrowupdating="CustomersGridView_RowUpdating"  
        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]"
        updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

Hinweise

Verwenden Sie NewValues die-Eigenschaft (Wörterbuch), um auf die Werte der überarbeiteten nicht Schlüsselfelder in der zu aktualisierenden Zeile zuzugreifen.Use the NewValues property (dictionary) to access the values of the revised non-key fields in the row to update.

Hinweis

Das Feld bzw. die Felder des Primärschlüssels sind nicht in diesem Wörterbuch enthalten.The primary key field or fields are not included in this dictionary. Verwenden Sie die Keys -Eigenschaft, um auf die Werte des Felds bzw. der Felder des Primärschlüssels zuzugreifen.To access the values of the primary key field or fields, use the Keys property. Verwenden Sie die OldValues -Eigenschaft, um auf die ursprünglichen Werte der nicht Schlüsselfelder in der Zeile zuzugreifen.To access the original values of the non-key fields in the row, use the OldValues property.

Die NewValues -Eigenschaft wird automatisch mit den Name-Wert-Paaren der überarbeiteten nicht Schlüsselfelder in der Zeile aufgefüllt.The NewValues property is automatically populated with the name/value pairs of the revised non-key fields in the row. Der NewValues -Eigenschaft wird für jedes nicht-Schlüsselfeld in der Zeile ein separater Eintrag hinzugefügt.A separate entry is added to the NewValues property for each non-key field in the row.

Um den Feldnamen eines Eintrags zu ermitteln, verwenden DictionaryEntry.Key Sie die- System.Collections.DictionaryEntry Eigenschaft eines-Objekts NewValues , das im Wörterbuch enthalten ist.To determine the field name of an entry, use the DictionaryEntry.Key property of a System.Collections.DictionaryEntry object contained in the NewValues dictionary. Um den Wert eines Eintrags zu ermitteln, verwenden DictionaryEntry.Value Sie die-Eigenschaft.To determine the value of an entry, use the DictionaryEntry.Value property.

Gilt für:

Siehe auch