다음을 통해 공유


ListViewDeletedEventArgs.Keys 속성

정의

삭제된 항목의 키를 가져옵니다.

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

속성 값

삭제된 항목의 키입니다.

예제

다음 예제에서는 사용 하는 방법의 Keys 삭제 된 항목에 대 한 키 필드의 값에 액세스 하는 속성입니다.

<%@ 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 ContactsListView_ItemDeleted(Object sender, ListViewDeletedEventArgs 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>ListViewDeletedEventArgs Keys and Values Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListViewDeletedEventArgs Keys and Values Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
                
      <br/>
      
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemDeleted="ContactsListView_ItemDeleted"  
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" runat="server" id="tblContacts" width="640px">
            <tr id="itemPlaceholder" runat="server"></tr>
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|<< " LastPageText=" >>|"
                NextPageText=" > " PreviousPageText=" < " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td valign="top">
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Bind("FirstName") %>' />
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Bind("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Bind("EmailAddress") %>' />
            </td>
            <td>
              <asp:LinkButton ID="DeleteButton" runat="server" 
                CommandName="Delete" 
                Text="Delete" 
                OnClientClick="return confirm('Are you sure?');" />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
                 
      <br/><br />
         
      <asp:Label ID="KeysMessageLabel"
        ForeColor="Red"
        runat="server"/>
          
      <br/>
          
      <asp:Label ID="ValuesMessageLabel"
        ForeColor="Red"
        runat="server"/>
            
      <!-- This example uses Microsoft SQL Server and connects    -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET  -->
      <!-- expression to retrieve the connection string value     -->
      <!-- from the Web.config file.                              -->            
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] FROM Person.Contact"
        DeleteCommand="DELETE FROM Person.Contact WHERE [ContactID] = @ContactID">
          <DeleteParameters>
              <asp:Parameter Name="ContactID" Type="Int32" />
          </DeleteParameters>
      </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 ContactsListView_ItemDeleted(sender As Object, e As ListViewDeletedEventArgs)

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

    For Each entry As DictionaryEntry In e.Keys
      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/>"

    For Each entry As DictionaryEntry In e.Values
      DisplayValue(entry, ValuesMessageLabel)
    Next
  End Sub

  Sub DisplayValue(entry As DictionaryEntry, 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
      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 id="Head1" runat="server">
    <title>ListViewDeletedEventArgs Keys and Values Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListViewDeletedEventArgs Keys and Values Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
                
      <br/>
      
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemDeleted="ContactsListView_ItemDeleted"  
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" runat="server" id="tblContacts" width="640px">
            <tr id="itemPlaceholder" runat="server"></tr>
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|<< " LastPageText=" >>|"
                NextPageText=" > " PreviousPageText=" < " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td valign="top">
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Bind("FirstName") %>' />
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Bind("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Bind("EmailAddress") %>' />
            </td>
            <td>
              <asp:LinkButton ID="DeleteButton" runat="server" 
                CommandName="Delete" 
                Text="Delete" 
                OnClientClick="return confirm('Are you sure?');" />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
                 
      <br/><br />
         
      <asp:Label ID="KeysMessageLabel"
        ForeColor="Red"
        runat="server"/>
          
      <br/>
          
      <asp:Label ID="ValuesMessageLabel"
        ForeColor="Red"
        runat="server"/>
            
      <!-- This example uses Microsoft SQL Server and connects    -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET  -->
      <!-- expression to retrieve the connection string value     -->
      <!-- from the Web.config file.                              -->            
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] FROM Person.Contact"
        DeleteCommand="DELETE FROM Person.Contact WHERE [ContactID] = @ContactID">
          <DeleteParameters>
              <asp:Parameter Name="ContactID" Type="Int32" />
          </DeleteParameters>
      </asp:SqlDataSource>

    </form>
  </body>
</html>

설명

사용 합니다 Keys 키 필드의 값에 액세스 하는 속성 (지정 된 대로 ListView.DataKeyNames 속성) 삭제 된 항목에 대 한 합니다. 예를 들어 삭제 된 항목의 로그를 유지할 이러한 값을 사용할 수 있습니다.

참고

이 속성의 키 필드에만 포함합니다. 키가 아닌 필드에 액세스 하려면 사용 된 Values 속성입니다.

Keys 속성은 IOrderedDictionary 인터페이스를 구현하는 개체를 반환합니다. 개체에 DictionaryEntry 삭제 된 항목의 키 필드를 나타내는 개체입니다.

적용 대상

추가 정보