DataKeyArray 클래스

정의

DataKey 개체의 컬렉션을 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class DataKeyArray sealed : System::Collections::ICollection, System::Web::UI::IStateManager
public sealed class DataKeyArray : System.Collections.ICollection, System.Web.UI.IStateManager
type DataKeyArray = class
    interface ICollection
    interface IEnumerable
    interface IStateManager
Public NotInheritable Class DataKeyArray
Implements ICollection, IStateManager
상속
DataKeyArray
구현

예제

다음 코드 예제에서는 인덱서를 사용 하 여 검색 하는 방법에 설명 된 DataKey 에서 개체를 DataKeyArray 컬렉션입니다.


<%@ 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 CustomerGridView_DataBound(Object sender, EventArgs e)
  {           
    // Use the indexer to retrieve the DataKey object for the 
    // first record.
    DataKey key = CustomerGridView.DataKeys[0];

    // Display the value of the primary key for the first
    // record displayed in the GridView control.
    MessageLabel.Text = "The primary key of the first record displayed is " +
      key.Value.ToString() + ".";
  }

  void CopyArray_Click(Object sender, EventArgs e)
  {
      DataKeyArray theKeys = CustomerGridView.DataKeys;
      DataKey[] myNewArray = new DataKey[theKeys.Count];
      theKeys.CopyTo(myNewArray, 0);
      Label2.Visible = true;

      // Display first page key values from the new array.
      for (int i = 0; i < myNewArray.Length; i++)
      {
          Label2.Text += "<br />" + myNewArray[i].Value;
      }

  }

</script>

<html  >

  <head id="Head1" runat="server">
    <title>DataKeyArray Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>DataKeyArray Example</h3>

        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          ondatabound="CustomerGridView_DataBound" 
          runat="server">

        </asp:gridview>

        <br/>

        <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="CustomerDataSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>" 
          runat="server"/>

        <asp:Button ID="CopyArray" 
            runat="server" 
            Text="Copy DataKeyArray to Array" 
            OnClick="CopyArray_Click" />

        <br />

        <asp:label id="Label2"
          runat="server"
          Visible="false"  
          Text="First page of Copied Array Key Values" />


      </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 CustomerGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles CustomerGridView.DataBound
          
    ' Use the indexer to retrieve the DataKey object for the 
    ' first record.
    Dim key As DataKey = CustomerGridView.DataKeys(0)

    ' Display the value of the primary key for the first
    ' record displayed in the GridView control.
    MessageLabel.Text = "The primary key of the first record displayed is " & _
      key.Value.ToString() & "."
  
    End Sub
    
    Sub CopyArray_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim theKeys As DataKeyArray = CustomerGridView.DataKeys
        Dim myNewArray(theKeys.Count - 1) As DataKey
        theKeys.CopyTo(myNewArray, 0)
        Label2.Visible = True

        ' Display first page key values from the new array.  
        For i As Integer = 0 To myNewArray.Length - 1
            Label2.Text &= "<br />" & myNewArray(i).Value
        Next i

    End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head id="Head1" runat="server">
    <title>DataKeyArray Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataKeyArray Example</h3>
                       
        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          runat="server">
            
        </asp:gridview>
        
        <br/>
        
        <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="CustomerDataSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>

        <asp:Button ID="CopyArray" 
            runat="server" 
            Text="Copy DataKeyArray to Array" 
            OnClick="CopyArray_Click" />

        <br />

        <asp:label id="Label2"
          runat="server"
          Visible="false"  
          Text="First page of Copied Array Key Values" />
            
      </form>
  </body>
</html>

다음 코드 예제에는 반복 하는 방법을 보여 줍니다.는 DataKeyArray 컬렉션입니다.


<%@ 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 CustomerGridView_DataBound(Object sender, EventArgs e)
  {    
    // Display the value of the primary key for each
    // record in the GridView control.
    MessageLabel.Text = "The primary key of each record displayed are: <br/><br/>";

    foreach (DataKey key in CustomerGridView.DataKeys)
    {
       MessageLabel.Text += key.Value.ToString() + "<br/>";
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DataKeyArray Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataKeyArray Example</h3>
                       
        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          ondatabound="CustomerGridView_DataBound" 
          runat="server">
            
        </asp:gridview>
        
        <br/>
        
        <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="CustomerDataSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
          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 CustomerGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles CustomerGridView.DataBound
    
    ' Display the value of the primary key for each
    ' record in the GridView control.
    MessageLabel.Text = "The primary key of each record displayed are: <br/><br/>"

    Dim key As DataKey
    For Each key In CustomerGridView.DataKeys
    
      MessageLabel.Text += key.Value.ToString() + "<br/>"
      
    Next
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DataKeyArray Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataKeyArray Example</h3>
                       
        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          runat="server">
            
        </asp:gridview>
        
        <br/>
        
        <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="CustomerDataSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>

설명

DataKeyArray 클래스는 저장 하 고 관리할 컬렉션 데 DataKey 개체입니다. DataKey 개체는 데이터 바인딩된 컨트롤에서 레코드의 기본 키를 나타냅니다. 일반적으로 데이터 바인딩된 컨트롤 표시 하는 여러 레코드 (같은 GridView 컨트롤) 사용 하 여는 DataKeyArray 저장할 개체입니다는 DataKey 컨트롤에 표시 된 레코드에 대 한 개체입니다.

DataKeyArray 클래스는 컬렉션의 항목에 액세스 하는 여러 방법을 지원 합니다.

  • 사용 하 여는 Item[] 인덱서를 직접 검색 하는 DataKey 특정 인덱스에서 컬렉션의 개체입니다.

  • 사용 된 GetEnumerator 메서드 컬렉션을 반복 하는 데 사용할 수 있는 열거자를 검색 합니다.

  • 사용 된 CopyTo 컬렉션의 항목에 액세스를 사용할 수 있는 배열 컬렉션의 항목을 복사 하는 방법입니다.

컬렉션에서 항목의 총 수를 확인 하려면 사용 된 Count 속성입니다.

생성자

DataKeyArray(ArrayList)

DataKeyArray 클래스의 새 인스턴스를 초기화합니다.

속성

Count

컬렉션의 항목 수를 가져옵니다.

IsReadOnly

컬렉션의 항목을 수정할 수 있는지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

DataKeyArray 컬렉션이 동기화되어 스레드로부터 안전하게 보호되는지 여부를 나타내는 값을 가져옵니다.

Item[Int32]

컬렉션의 지정한 인덱스에서 DataKey 개체를 가져옵니다.

SyncRoot

컬렉션에 대한 액세스 권한을 동기화하는 데 사용된 개체를 가져옵니다.

메서드

CopyTo(DataKey[], Int32)

이 컬렉션의 모든 항목을 배열의 지정된 인덱스에서 시작하여 지정된 DataKey 개체의 배열로 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

컬렉션의 모든 DataKey 개체를 포함하는 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

Array에 지정된 인덱스에서 시작하여 지정된 Array로 이 컬렉션의 모든 항목을 복사합니다.

IStateManager.IsTrackingViewState

DataKeyArray 개체에서 해당 뷰 상태의 변경 사항을 추적하는지 여부를 나타내는 값을 가져옵니다.

IStateManager.LoadViewState(Object)

이전에 저장된 DataKeyArray 개체의 뷰 상태를 로드합니다.

IStateManager.SaveViewState()

DataKeyArray 개체의 현재 뷰 상태를 저장합니다.

IStateManager.TrackViewState()

뷰 상태의 변경 사항을 추적하여 DataKeyArray 개체에 이 변경 사항을 저장할 시작 위치를 표시합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보