GridViewUpdateEventArgs.NewValues Özellik

Tanım

Güncelleştirilecek satırdaki anahtar olmayan alan adı/değer çiftlerinin düzeltilmiş değerlerini içeren bir sözlük alır.

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

Özellik Değeri

IOrderedDictionary

IOrderedDictionary Güncelleştirilecek satırdaki anahtar olmayan alan adı/değer çiftlerinin düzeltilmiş değerlerini içeren bir nesne.

Örnekler

Aşağıdaki örnek, veri kaynağını güncelleştirmeden önce kullanıcı tarafından sağlanan tüm değerleri HTML kodlamak için özelliğinin nasıl kullanılacağını NewValues gösterir.


<%@ 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>

Açıklamalar

Güncelleştirilecek satırdaki NewValues düzeltilmiş anahtar olmayan alanların değerlerine erişmek için özelliğini (sözlük) kullanın.

Not

Birincil anahtar alanı veya alanları bu sözlüğe dahil değildir. Birincil anahtar alanının veya alanlarının değerlerine erişmek için özelliğini kullanın Keys . Satırdaki anahtar olmayan alanların özgün değerlerine erişmek için özelliğini kullanın OldValues .

NewValues özelliği, satırdaki düzeltilmiş anahtar olmayan alanların ad/değer çiftleriyle otomatik olarak doldurulur. Satırdaki NewValues anahtar olmayan her alan için özelliğine ayrı bir giriş eklenir.

Bir girdinin alan adını belirlemek için, sözlükte NewValues bulunan bir System.Collections.DictionaryEntry nesnenin özelliğini kullanınDictionaryEntry.Key. Bir girdinin değerini belirlemek için özelliğini kullanın DictionaryEntry.Value .

Şunlara uygulanır

Ayrıca bkz.