OldValues Property
Collapse the table of content
Expand the table of content

GridViewUpdateEventArgs.OldValues Property

Gets a dictionary containing the original field name/value pairs in the row to update.

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

public IOrderedDictionary OldValues { get; }

Property Value

Type: System.Collections.Specialized.IOrderedDictionary
An System.Collections.Specialized.IOrderedDictionary object that contains the original values of the field name/value pairs in the row to update.

Use the OldValues property (dictionary) to access the original values of the fields in the row to update. This dictionary contains all fields in the row except the key fields. The key fields are defined in the DataKeyNames property of a GridView control.


You can access the key fields of the row by using the Keys property. To access the revised values of the non-key fields in the row, use the NewValues property.

The OldValues property is automatically populated with the original values of all the field name/value pairs in the row. A separate entry is added to the OldValues property for each 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 OldValues dictionary. To determine the value of an entry, use the DictionaryEntry.Value property.

The following example demonstrates how to use the OldValues property to access the original values of the fields in the row to update. The values are then written to a log file of updated records.

<%@ Page language="C#" %>
<%@ import namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    void EmployeesGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)

        // Record the update operation in a log file. 

        // Create the log text. 
        String logText = "";

        // Append the original field values to the log text. 
        foreach (DictionaryEntry valueEntry in e.OldValues)
            logText += valueEntry.Key + "=" + valueEntry.Value + ";";

        // Append the text to a log file.
        StreamWriter sw;
        sw = File.AppendText(Server.MapPath(null) + "\\updatelog.txt");


    void EmployeesGridView_RowUpdated(Object sender, GridViewUpdatedEventArgs e)

        if (e.Exception == null)
            // The update operation succeeded. Clear the message label.
            Message.Text = "";
            // The update operation failed. Display an error message.
            Message.Text = e.AffectedRows.ToString() + " rows updated. " + e.Exception.Message;
            e.ExceptionHandled = true;



<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>GridViewUpdateEventArgs OldValues Example</title>
        <form id="Form1" runat="server">

            <h3>GridViewUpdateEventArgs OldValues Example</h3>

            <asp:label id="Message"


            <!-- The GridView control automatically sets the columns     -->
            <!-- specified in the datakeynames attribute as read-only.   -->
            <!-- No input controls are rendered for these columns in     -->
            <!-- edit mode.                                              -->
            <asp:gridview id="EmployeesGridView" 

            <!-- This example uses Microsoft SQL Server and connects -->
            <!-- to the Northwind sample database.                   -->
            <asp:sqldatasource id="EmployeesSqlDataSource"  
                selectcommand="SELECT [EmployeeID], [LastName], [FirstName], [HireDate] FROM [Employees]"
                updatecommand="UPDATE [Employees] SET [LastName] = @LastName, [FirstName] = @FirstName, [HireDate] = @HireDate WHERE [EmployeeID] = @EmployeeID" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                runat="server" >


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

© 2016 Microsoft