GridViewUpdateEventArgs.NewValues GridViewUpdateEventArgs.NewValues GridViewUpdateEventArgs.NewValues GridViewUpdateEventArgs.NewValues Property

정의

업데이트할 행에 있는 키가 아닌 필드 이름/값 쌍의 수정된 값이 들어 있는 사전을 가져옵니다.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

속성 값

업데이트할 행에 있는 키가 아닌 필드 이름/값 쌍의 수정된 값이 들어 있는 IOrderedDictionary 개체입니다.An IOrderedDictionary object containing the revised values of the non-key field name/value pairs in the row to update.

예제

다음 예제에서는 사용 하는 방법에 설명 합니다 NewValues 속성 모든 값이 데이터 원본을 업데이트 하기 전에 사용자가 제공한 HTML로 인코딩합니다.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>

설명

사용 된 NewValues 업데이트할 행의 수정 된 키가 아닌 필드의 값에 액세스 하려면 속성 (사전)입니다.Use the NewValues property (dictionary) to access the values of the revised non-key fields in the row to update.

참고

기본 키 필드 또는 필드를이 사전에 포함 되지 않습니다.The primary key field or fields are not included in this dictionary. 기본 키 필드 또는 필드의 값에 액세스 하려면 사용 된 Keys 속성입니다.To access the values of the primary key field or fields, use the Keys property. 행 키가 아닌 필드의 원래 값에 액세스 하려면 사용 된 OldValues 속성입니다.To access the original values of the non-key fields in the row, use the OldValues property.

NewValues 속성은 행의 수정 된 키가 아닌 필드 이름/값 쌍을 자동으로 채워집니다.The NewValues property is automatically populated with the name/value pairs of the revised non-key fields in the row. 별도 항목에 추가 됩니다는 NewValues 행의 각 키가 아닌 필드에 대 한 속성입니다.A separate entry is added to the NewValues property for each non-key field in the row.

항목의 필드 이름을 확인 하려면 사용 합니다 DictionaryEntry.Key 의 속성을 System.Collections.DictionaryEntry 에 포함 된 개체는 NewValues 사전.To determine the field name of an entry, use the DictionaryEntry.Key property of a System.Collections.DictionaryEntry object contained in the NewValues dictionary. 항목의 값을 확인 하려면 사용 된 DictionaryEntry.Value 속성입니다.To determine the value of an entry, use the DictionaryEntry.Value property.

적용 대상

추가 정보