DetailsViewDeleteEventArgs.Keys DetailsViewDeleteEventArgs.Keys DetailsViewDeleteEventArgs.Keys DetailsViewDeleteEventArgs.Keys Property

정의

삭제된 항목의 키 필드 값과 해당 이름이 들어 있는 키 필드 이름/값 쌍의 정렬된 사전을 가져옵니다.Gets an ordered dictionary of key field name/value pairs that contains the names and values of the key fields of the deleted items.

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

속성 값

삭제할 항목과 일치시키는 데 사용되는 키 필드 이름/값 쌍의 정렬된 사전이 들어 있는 IOrderedDictionary입니다.An IOrderedDictionary that contains an ordered dictionary of key field name/value pairs used to match the item to delete.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 Keys 삭제할 레코드에 대 한 키 필드의 값에 액세스 하는 속성입니다.The following code example demonstrates how to use the Keys property to access the value of the key field for the record being deleted.


<%@ 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 CustomerDetailsView_ItemDeleting(Object sender, 
    DetailsViewDeleteEventArgs e)
  {

    // Get customer ID and name from the Keys and Values
    // properties.
    String keyValue = e.Keys["CustomerID"].ToString();
    String customerName = e.Values["CompanyName"].ToString();

    // Cancel the delete operation if the user attempts to 
    // delete protected record. In this example, records
    // with a customer ID that starts with with "A" cannot
    // be deleted.
    if (keyValue.StartsWith("A"))
    {
      e.Cancel = true;
      MessageLabel.Text = "You cannot delete " +
        customerName + ". This customer is protected.";
    }
    else
    {
      MessageLabel.Text = "Row " + e.RowIndex.ToString() + 
        " deleted.";
    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewDeleteEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewDeleteEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          onitemdeleting="CustomerDetailsView_ItemDeleting" 
          runat="server">
            
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <asp:label id="MessageLabel"
          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 CustomerDetailsView_ItemDeleting(ByVal sender As Object, _
    ByVal e As DetailsViewDeleteEventArgs)

    ' Get customer ID and name from the Keys and Values
    ' properties.
    Dim keyValue As String = e.Keys("CustomerID").ToString()
    Dim customerName As String = e.Values("CompanyName").ToString()

    ' Cancel the delete operation if the user attempts to 
    ' delete protected record. In this example, records
    ' with a customer ID that starts with with "A" cannot
    ' be deleted.
    If keyValue.StartsWith("A") Then

      e.Cancel = True
      MessageLabel.Text = "You cannot delete " & _
        customerName & ". This customer is protected."
    
    Else
    
      MessageLabel.Text = "Row " & e.RowIndex.ToString() & _
        " deleted."
    
    End If
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewDeleteEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewDeleteEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          onitemdeleting="CustomerDetailsView_ItemDeleting" 
          runat="server">
            
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <asp:label id="MessageLabel"
          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>

설명

사용 된 Keys 삭제할 레코드에 대 한 키 필드의 값에 액세스 하는 속성입니다.Use the Keys property to access the values of the key field or fields for the record to be deleted. 예를 들어, 레코드를 삭제 하거나 삭제 된 레코드의 로그를 유지할 레코드를 변경 하려면 삭제 하기 전에 확인 하려면 이러한 값을 사용할 수 있습니다.For example, you can use these values to verify the record before deleting it, to change the record to delete, or to keep a log of deleted records.

참고

이 속성의 키 필드에만 포함합니다.This property contains only the key fields. 키가 아닌 필드 이름/값 쌍 값에 액세스 하려면 사용 된 Values 속성입니다.To access the name/value pair values for the non-key fields, use the Values property.

합니다 Keys 속성을 구현 하는 개체를 반환 합니다.는 IOrderedDictionary 인터페이스입니다.The Keys property returns an object that implements the IOrderedDictionary interface. 개체에 DictionaryEntry 키 필드를 나타내는 개체입니다.The object contains DictionaryEntry objects that represent the key fields.

참고

인덱스를 이용할 수 있습니다 가기로 IOrderedDictionary 키 필드 값에 액세스 하는 개체입니다.As a shortcut, you can also use the indexer of the IOrderedDictionary object to access the key field values. 인덱서를 사용 하 여 장점은 키 필드 값이 직접 반환 된다는 것입니다.The advantage in using the indexer is that it returns key field values directly.

이 속성은 읽기 전용입니다. 키 필드 값을 수정할 수 있습니다는 IOrderedDictionary 개체를 반환 합니다.This property is read-only; however, you can modify the key field values of the IOrderedDictionary object it returns. 키 필드 값을 변경한 경우 해당 레코드는 데이터 원본에서 삭제 됩니다.If you change the key field values, the corresponding record is be deleted from the data source.

적용 대상

추가 정보