DataKey クラスとは? わかりやすく解説

DataKey クラス

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

データ バインド コントロール内のレコード1 つまたは複数主キー フィールド表します

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

Public Class DataKey
    Implements IStateManager
public class DataKey : IStateManager
public ref class DataKey : IStateManager
public class DataKey implements IStateManager
public class DataKey implements IStateManager
解説解説

DataKey クラスは、データ バインド コントロール内のレコード主キーを表すために使用されます。レコード主キーは、データ ソース1 つ上のフィールド構成できますDataKey クラスコレクションではありませんが、キー フィールドの値を複数格納できますDataKey クラスコンストラクタ1 つ呼び出されると、キー フィールドの値が代入されます。DataKey オブジェクトからキー フィールドの値を取得する方法は、次のとおりです。

通常DataKey オブジェクトは、データ バインド コントロールDataKeyNames プロパティ設定されている場合にそのコントロールによって自動生成されますDataKey オブジェクトには、DataKeyNames プロパティ内で指定され1 つ上のキー フィールドの値が格納されます。一度1 つレコードだけを表示するデータ バインド コントロール (DetailsView または FormView など) には、通常、そのコントロールDataKey プロパティ内に現在表示されているレコードDataKey オブジェクト格納されます。一度複数レコード表示するデータ バインド コントロール (GridView など) には、通常、DataKeyArray コレクション内にあるこのコントロールの各レコードDataKey オブジェクト格納されます。その後DataKeyArray コレクションコントロールDataKeys プロパティ格納されます。

使用例使用例

DataKey オブジェクトValue プロパティ使用して DetailsView コントロール内のレコード主キーの値を確認するコード例次に示します

<%@ Page language="VB" %>

<script runat="server">

  Sub CustomerDetailsView_DataBound(ByVal sender
 As Object, ByVal e As
 EventArgs) Handles CustomerDetailsView.DataBound

    ' Get the DataKey object for the current record.
    Dim key As DataKey = CustomerDetailsView.DataKey
    
    ' Display the the value of the key field.
    MessageLabel.Text = "The key field value for the displayed
 record is " & _
      key.Value.ToString() & "."
    
  End Sub
  
</script>

<html>

  <body>
    <form runat="server">
        
      <h3>DataKey Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          runat="server">
            
        </asp:detailsview>
        
        <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="DetailsViewSource"
          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 CustomerDetailsView_DataBound(Object sender, EventArgs
 e)
  {
    // Get the DataKey object for the current record.
    DataKey key = CustomerDetailsView.DataKey;
    
    // Display the the value of the key field.
    MessageLabel.Text = "The key field value for the displayed
 record is " + 
      key.Value.ToString() + ".";
  }
  
</script>

<html>

  <body>
    <form runat="server">
        
      <h3>DataKey Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          ondatabound="CustomerDetailsView_DataBound" 
          runat="server">
            
        </asp:detailsview>
        
        <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="DetailsViewSource"
          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.DataKey
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataKey メンバ
System.Web.UI.WebControls 名前空間
DataKeyArray
DetailsView.DataKey
FormView.DataKey
GridView.DataKeys
Values
Item
Value



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataKey クラス」の関連用語

DataKey クラスのお隣キーワード
検索ランキング

   

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



DataKey クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS