Export (0) Print
Expand All

GridViewUpdateEventArgs.NewValues Property

Gets a dictionary containing the revised values of the non-key field name/value pairs in the row to update.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public IOrderedDictionary NewValues { get; }

Property Value

Type: System.Collections.Specialized.IOrderedDictionary
An System.Collections.Specialized.IOrderedDictionary object containing the revised values of the non-key field name/value pairs in the row to update.

Use the NewValues property (dictionary) to access the values of the revised non-key fields in the row to update.

NoteNote

The primary key field or fields are not included in this dictionary. To access the values of the primary key field or fields, use the Keys property. To access the original values of the non-key fields in the row, use the OldValues property.

The NewValues property is automatically populated with the name/value pairs of the revised non-key fields in the row. A separate entry is added to the NewValues property for each non-key field in the row.

To determine the field name of an entry, use the DictionaryEntry.Key property of a System.Collections.DictionaryEntry object contained in the NewValues dictionary. To determine the value of an entry, use the DictionaryEntry.Value property.

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>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft