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

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

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

NewValues プロパティを使用して、ユーザーが入力したすべての値をデータ ソースの更新前に HTML エンコードする方法を次の例に示します。
<%@ Page language="VB" %> <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> <body> <form 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="C#" %> <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> <body> <form 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>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGridViewUpdateEventArgs.NewValues プロパティを検索する場合は、下記のリンクをクリックしてください。

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