DetailsViewDeletedEventArgs.Values Свойство

Определение

Получает словарь пар "имя/значение" неключевых полей удаленных записей.

public:
 property System::Collections::Specialized::IOrderedDictionary ^ Values { System::Collections::Specialized::IOrderedDictionary ^ get(); };
public System.Collections.Specialized.IOrderedDictionary Values { get; }
member this.Values : System.Collections.Specialized.IOrderedDictionary
Public ReadOnly Property Values As IOrderedDictionary

Значение свойства

IOrderedDictionary

IOrderedDictionary, содержащий словарь пар "имя/значение" неключевых полей удаляемых записей.

Примеры

В следующем примере кода показано, как использовать Values свойство для доступа к значениям неключевых полей удаленной записи.


<%@ 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 StoresDetailView_ItemDeleted(Object sender, 
  DetailsViewDeletedEventArgs e)
  {
    // Display the value of the key fields in the Keys property.
    KeysMessageLabel.Text =
      "The key fields for the deleted record are: <br/>";

    foreach (DictionaryEntry entry in e.Keys)
    {
      DisplayValue(entry, KeysMessageLabel);
    }

    // Display the value of the non-key fields in the Values 
    // property.
    ValuesMessageLabel.Text =
      "The non-key fields for the deleted record are: <br/>";
    
    foreach (DictionaryEntry entry in e.Values)
    {
      DisplayValue(entry, ValuesMessageLabel);
    }
  }

  void DisplayValue(DictionaryEntry entry, Label displayLabel)
  {
    // Display the field name contained in the DictionaryEntry object.
    if (entry.Key != null)
    {
      displayLabel.Text += "Name=" + entry.Key.ToString() + ", ";
    }
    else
    {
      displayLabel.Text += "Name=null, ";
    }

    // Display the field value contained in the DictionaryEntry object.
    if (entry.Value != null)
    {
      displayLabel.Text += "Value=" + entry.Value.ToString() + "<br/>";
    }
    else
    {
      displayLabel.Text += "Value=null<br/>";
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewDeletedEventArgs Keys and Values Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewDeletedEventArgs Keys and Values Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          onitemdeleted="StoresDetailView_ItemDeleted" 
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <asp:label id="KeysMessageLabel"
          forecolor="Red"
          runat="server"/>
          
        <br/><br/>
          
        <asp:label id="ValuesMessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- 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="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          deletecommand="Delete [Customers] 
            Where [CustomerID]=@CustomerID"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </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 StoresDetailView_ItemDeleted(ByVal sender As Object, _
    ByVal e As DetailsViewDeletedEventArgs)

    Dim entry As DictionaryEntry
    Dim i As Integer
    
    ' Display the value of the key fields in the Keys property.
    KeysMessageLabel.Text = _
      "The key fields for the deleted record are: <br/>"

    ' In VB, you cannot iterate through the DictionaryEntry objects
    ' in the Keys property directly. Use the CopyTo method to 
    ' copy the objects to an array first.
    Dim keysArray(e.Keys.Count - 1) As DictionaryEntry
    e.Keys.CopyTo(keysArray, 0)
    
    ' Iterate through the array and display its values.
    For Each entry In keysArray
    
      DisplayValue(entry, KeysMessageLabel)
    
    Next

    ' Display the value of the non-key fields in the Values 
    ' property.
    ValuesMessageLabel.Text = _
      "The non-key fields for the deleted record are: <br/>"

    Dim valuesArray(e.Values.Count - 1) As DictionaryEntry
    e.Values.CopyTo(valuesArray, 0)

    For Each entry In valuesArray
    
      DisplayValue(entry, ValuesMessageLabel)
    
    Next
    
  End Sub

  Sub DisplayValue(ByVal entry As DictionaryEntry, _
    ByVal displayLabel As Label)
  
    ' Display the field name contained in the DictionaryEntry object.
    If entry.Key IsNot Nothing Then
    
      displayLabel.Text &= "Name=" & entry.Key.ToString() & ", "
    
    Else
    
      displayLabel.Text &= "Name=null, "
      
    End If

    ' Display the field value contained in the DictionaryEntry object.
    If entry.Value IsNot Nothing Then
    
      displayLabel.Text &= "Value=" & entry.Value.ToString() & "<br/>"
    
    Else
    
      displayLabel.Text &= "Value=null<br/>"
      
    End If
        
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewDeletedEventArgs Keys and Values Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewDeletedEventArgs Keys and Values Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          onitemdeleted="StoresDetailView_ItemDeleted" 
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <asp:label id="KeysMessageLabel"
          forecolor="Red"
          runat="server"/>
          
        <br/><br/>
          
        <asp:label id="ValuesMessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- 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="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          deletecommand="Delete [Customers] 
            Where [CustomerID]=@CustomerID"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
         runat="server"/>
            
      </form>
  </body>
</html>

Комментарии

Values Используйте свойство для доступа к значениям полей, не являющихся ключами, для удаления записи. Например, эти значения можно использовать для хранения журнала удаленных записей.

Примечание

Это свойство не содержит ключевые поля записи. Чтобы получить доступ к ключевым полям Keys , используйте свойство.

Свойство Values возвращает IOrderedDictionary объект, реализующий IOrderedDictionary интерфейс. Объект содержит DictionaryEntry объекты, представляющие удаляемые неключовые поля записи.

Примечание

В качестве ярлыка IOrderedDictionary можно также использовать индексатор объекта для прямого доступа к значениям полей.

Применяется к

См. также раздел