DataKeyArrayとは? わかりやすく解説

DataKeyArray クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

DataKey オブジェクトのコレクションを表します。このクラスは継承できません。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 DataKeyArray
    Implements ICollection, IEnumerable, IStateManager
public sealed class DataKeyArray : ICollection,
 IEnumerable, IStateManager
public ref class DataKeyArray sealed : ICollection,
 IEnumerable, IStateManager
public final class DataKeyArray implements
 ICollection, IEnumerable, 
    IStateManager
public final class DataKeyArray implements
 ICollection, IEnumerable, 
    IStateManager
解説解説
使用例使用例

インデクサを使用して DataKeyArray コレクションから DataKey オブジェクトを取得する方法を次のコード例に示します。

<%@ Page language="VB" %>

<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 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
  
</script>

<html>

  <body>
    <form 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>

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

<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 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() + ".";
  }
  
</script>

<html>

  <body>
    <form 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>

DataKeyArray コレクションを反復処理する方法を次のコード例に示します。

<%@ Page language="VB" %>

<script runat="server">

  Sub CustomerGridView_DataBound(ByVal sender
 As Object, ByVal e As
 EventArgs) Handles CustomerGridView.DataBound
    
    ' Display the 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>

  <body>
    <form 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>

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

<script runat="server">

  void CustomerGridView_DataBound(Object sender, EventArgs e)
  {    
    // Display the 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>

  <body>
    <form 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>

.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
  System.Web.UI.WebControls.DataKeyArray
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataKeyArray メンバ
System.Web.UI.WebControls 名前空間
DataKey クラス
ICollection
IStateManager
CopyTo
GetEnumerator
Item
Count

DataKeyArray コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

DataKeyArray クラスの新しいインスタンスを初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataKeyArray クラス
DataKeyArray メンバ
System.Web.UI.WebControls 名前空間
DataKey クラス
System.Collections.ArrayList
GridView.DataKeys

DataKeyArray プロパティ


パブリック プロパティパブリック プロパティ

明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Web.UI.IStateManager.IsTrackingViewState DataKeyArray オブジェクトがビューステートの変更を追跡しているかどうかを示す値を取得します。
参照参照

関連項目

DataKeyArray クラス
System.Web.UI.WebControls 名前空間
DataKey クラス
ICollection
IStateManager
CopyTo
GetEnumerator
Item
Count

DataKeyArray メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo 指定した System.Array にこのコレクションのすべての項目をコピーします。コピー操作は、System.Array 内の指定したインデックス位置から開始されます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.LoadViewState 以前に保存した DataKeyArray オブジェクトのビューステートを読み込みます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.SaveViewState DataKeyArray オブジェクトの現在のビューステートを保存します。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.TrackViewState DataKeyArray オブジェクトに対するビューステートの変更の追跡と保存を始める開始点にマークを付けます。
参照参照

関連項目

DataKeyArray クラス
System.Web.UI.WebControls 名前空間
DataKey クラス
ICollection
IStateManager
CopyTo
GetEnumerator
Item
Count

DataKeyArray メンバ

DataKey オブジェクトのコレクションを表します。このクラスは継承できません。

DataKeyArray データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DataKeyArray DataKeyArray クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo 指定した System.Array にこのコレクションのすべての項目をコピーします。コピー操作は、System.Array 内の指定したインデックス位置から開始されます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.LoadViewState 以前に保存した DataKeyArray オブジェクトのビューステートを読み込みます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.SaveViewState DataKeyArray オブジェクトの現在のビューステートを保存します。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.TrackViewState DataKeyArray オブジェクトに対するビューステートの変更の追跡と保存を始める開始点にマークを付けます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.IsTrackingViewState DataKeyArray オブジェクトがビューステートの変更を追跡しているかどうかを示す値を取得します。
参照参照

関連項目

DataKeyArray クラス
System.Web.UI.WebControls 名前空間
DataKey クラス
ICollection
IStateManager
CopyTo
GetEnumerator
Item
Count



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataKeyArray」の関連用語

DataKeyArrayのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataKeyArrayのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS