다음을 통해 공유


DetailsView.DataKeyNames 속성

정의

데이터 소스에 대한 키 필드의 이름이 들어 있는 배열을 가져오거나 설정합니다.

public:
 virtual property cli::array <System::String ^> ^ DataKeyNames { cli::array <System::String ^> ^ get(); void set(cli::array <System::String ^> ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.StringArrayConverter))]
public virtual string[] DataKeyNames { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.StringArrayConverter))>]
member this.DataKeyNames : string[] with get, set
Public Overridable Property DataKeyNames As String()

속성 값

String[]

데이터 소스의 키 필드 이름이 들어 있는 배열입니다.

특성

예제

다음 코드 예제에서는 컨트롤에 바인딩된 데이터 원본에 대 한 키 필드를 식별 하는 속성을 사용 DataKeyNames 하는 DetailsView 방법을 보여 줍니다.


<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView AutoGenerateDeleteButton Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AutoGenerateDeleteButton Example</h3>
                
        <asp:detailsview id="CustomersDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"  
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- 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" runat="server" 
            ConnectionString=
              "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], 
              [CompanyName], [Address], [City], [PostalCode], [Country]) 
              VALUES (@CustomerID, @CompanyName, @Address, @City, 
              @PostalCode, @Country)"
            SelectCommand="Select [CustomerID], [CompanyName], 
              [Address], [City], [PostalCode], [Country] From 
              [Customers]">
        </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView AutoGenerateDeleteButton Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AutoGenerateDeleteButton Example</h3>
                
        <asp:detailsview id="CustomersDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"  
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- 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" runat="server" 
            ConnectionString=
              "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], 
              [CompanyName], [Address], [City], [PostalCode], [Country]) 
              VALUES (@CustomerID, @CompanyName, @Address, @City, 
              @PostalCode, @Country)"
            SelectCommand="Select [CustomerID], [CompanyName], 
              [Address], [City], [PostalCode], [Country] From 
              [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

설명

DataKeyNames 속성을 사용하여 데이터 원본의 기본 키를 나타내는 필드 이름의 쉼표로 구분된 목록을 지정합니다. 속성이 DataKeyNames 설정 DetailsView 되면 컨트롤은 현재 레코드의 키 필드 또는 필드를 나타내는 개체를 자동으로 만들고 DataKey 속성에 DataKey 저장합니다. AutoGenerateColumns 속성도 설정true되면 컨트롤은 DetailsView 속성에 지정된 DataKeyNames 필드 또는 필드가 읽기 전용인지 자동으로 확인합니다.

참고

작동하려면 컨트롤의 DataKeyNames 자동 업데이트, 삭제 및 삽입 기능에 DetailsView 대한 속성을 설정해야 합니다.

행 필드의 Visible 속성을 설정 false하면 행이 컨트롤에 DetailsView 표시되지 않고 행의 데이터가 클라이언트로 왕복하지 않습니다. 라운드 트립을 만들기 위해 표시되지 않는 행의 데이터를 원하는 경우 속성에 필드 이름을 DataKeyNames 추가합니다.

적용 대상

추가 정보