GridViewUpdateEventArgs.OldValues プロパティ
アセンブリ: System.Web (system.web.dll 内)

更新する行のフィールドの名前と値のペアの元の値が格納されている System.Collections.Specialized.IOrderedDictionary オブジェクト。

OldValues プロパティ (ディクショナリ) を使用して、更新する行のフィールドの元の値にアクセスします。このディクショナリには、キー フィールドを含め、行のすべてのフィールドが格納されています。
![]() |
---|
Keys プロパティを使用して行のキー フィールドにアクセスすることもできます。行のキー以外のフィールドの改訂後の値にアクセスするには、NewValues プロパティを使用します。 |
OldValues プロパティには、行のすべてのフィールドの名前と値のペアの元の値が自動的に格納されます。行のフィールドごとに別のエントリが OldValues プロパティに追加されます。
エントリのフィールド名を確認するには、OldValues ディクショナリに格納されている System.Collections.DictionaryEntry オブジェクトの DictionaryEntry.Key プロパティを使用します。エントリの値を確認するには、DictionaryEntry.Value プロパティを使用します。

OldValues プロパティを使用して、更新する行のフィールドの元の値にアクセスする方法を次の例に示します。その後、更新されたレコードのログ ファイルに値が書き込まれます。
<%@ Page language="VB" %> <%@ 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"> Sub EmployeesGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) ' Record the update operation in a log file. ' Create the log text. Dim logText As String = "" ' Append the key field values to the log text. Dim i As Integer For i = 0 To e.OldValues.Count - 1 logText += e.OldValues(i) & ";" Next ' Append the text to a log file. Dim sw As StreamWriter sw = File.AppendText(Server.MapPath(Nothing) & "\updatelog.txt") sw.WriteLine(logText) sw.Flush() sw.Close() End Sub Sub EmployeesGridView_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs) If e.Exception Is Nothing Then ' The update operation succeeded. Clear the message label. Message.Text = "" Else ' The update operation failed. Display an error message. Message.Text = e.AffectedRows.ToString() & " rows updated. " & e.Exception.Message e.ExceptionHandled = True End If End Sub </script> <html > <head runat="server"> <title>GridViewUpdateEventArgs Keys Example</title> </head> <body> <form id="Form1" runat="server"> <h3>GridViewUpdateEventArgs Keys Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- 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" datasourceid="EmployeesSqlDataSource" autogenerateeditbutton="True" onrowupdating="EmployeesGridView_RowUpdating" onrowupdated="EmployeesGridView_RowUpdated" runat="server"> </asp:gridview> <!-- 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" > <DeleteParameters> <asp:Parameter Name="EmployeeID" Type="Int32" /> </DeleteParameters> </asp:sqldatasource> </form> </body> </html>
<%@ 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 key field values to the log text. foreach (DictionaryEntry keyEntry in e.Keys) { logText += keyEntry.Key + "=" + keyEntry.Value + ";"; } // Append the text to a log file. StreamWriter sw; sw = File.AppendText(Server.MapPath(null) + "\\updatelog.txt"); sw.WriteLine(logText); sw.Flush(); sw.Close(); } void EmployeesGridView_RowUpdated(Object sender, GridViewUpdatedEventArgs e) { if (e.Exception == null) { // The update operation succeeded. Clear the message label. Message.Text = ""; } else { // The update operation failed. Display an error message. Message.Text = e.AffectedRows.ToString() + " rows updated. " + e.Exception.Message; e.ExceptionHandled = true; } } </script> <html > <head id="Head1" runat="server"> <title>GridViewUpdateEventArgs Keys Example</title> </head> <body> <form id="Form1" runat="server"> <h3>GridViewUpdateEventArgs OldValues Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- 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" datasourceid="EmployeesSqlDataSource" autogenerateeditbutton="True" onrowupdating="EmployeesGridView_RowUpdating" onrowupdated="EmployeesGridView_RowUpdated" runat="server"> </asp:gridview> <!-- 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" > <DeleteParameters> <asp:Parameter Name="EmployeeID" Type="Int32" /> </DeleteParameters> </asp:sqldatasource> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


GridViewUpdateEventArgs クラス
GridViewUpdateEventArgs メンバ
System.Web.UI.WebControls 名前空間
GridViewUpdateEventArgs.Keys プロパティ
GridViewUpdateEventArgs.NewValues プロパティ
GridViewUpdateEventArgs.Keys プロパティ
GridViewUpdateEventArgs.OldValues プロパティ
System.Collections.Specialized.IOrderedDictionary
DictionaryEntry.Key
DictionaryEntry.Value
Weblioに収録されているすべての辞書からGridViewUpdateEventArgs.OldValues プロパティを検索する場合は、下記のリンクをクリックしてください。

- GridViewUpdateEventArgs.OldValues プロパティのページへのリンク