DetailsView.DataKey プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DetailsView.DataKey プロパティの意味・解説 

DetailsView.DataKey プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

表示されているレコード主キーを表す DataKey オブジェクト取得します

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

Public Overridable ReadOnly
 Property DataKey As DataKey
Dim instance As DetailsView
Dim value As DataKey

value = instance.DataKey
public virtual DataKey DataKey { get; }
public:
virtual property DataKey^ DataKey {
    DataKey^ get ();
}
/** @property */
public DataKey get_DataKey ()
public function get DataKey
 () : DataKey

プロパティ
表示されているレコード主キーを表す DataKey

解説解説
使用例使用例

DataKey プロパティ使用して現在のレコードキー フィールド対応する値を確認する方法コード例次に示します

<%@ Page Language="VB" %>

<script runat="server">

    Sub CustomerDetailView_ItemUpdated(ByVal
 sender As Object, _
        ByVal e As DetailsViewUpdatedEventArgs)
    
        ' Create a dictionary that contains the key fields and values
 
        ' using the AllValues method of the DataKey object contained
 
        ' in the DataKey property.
        
        Dim keyList As IOrderedDictionary =
 _
            CustomerDetailsView.DataKey.Values

        ' Get the ArrayList objects that represent the key fields 
        ' and values.
        Dim keys As ArrayList = CType(keyList.Keys,
 ArrayList)
        Dim values As ArrayList = CType(keyList.Values,
 ArrayList)

        ' Get the key field and value for the current record. 
        Dim keyField As String
 = keys(0).ToString()
        Dim keyValue As String
 = values(0).ToString()
    
        ' Log the update operation using the key field and value.
        LogUpdate(keyField, keyValue)

    End Sub

    Sub LogUpdate(ByVal keyField As
 String, ByVal keyValue As
 String)
  
        ' Insert code to log the update operation.
  
    End Sub

</script>

<html>
<body>
    <form id="Form1" runat="server">
        <h3>
            DetailsView DataKey Example</h3>
        <asp:DetailsView ID="CustomerDetailsView"
 
          DataSourceID="DetailsViewSource" 
          DataKeyNames="CustomerID"
          AutoGenerateRows="true" 
          AutoGenerateEditButton="true" 
          AllowPaging="true" 
          OnItemUpdated="CustomerDetailView_ItemUpdated"
          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]"
            UpdateCommand="UPDATE [Customers] SET [CompanyName]
 = @CompanyName, 
            [Address] = @Address, [City] = @City,
            [PostalCode] = @PostalCode, [Country] = @Country
            WHERE [CustomerID] = @CustomerID"></asp:SqlDataSource>
    </form>
</body>
</html>
<%@ Page language="C#" %>

<script runat="server">

  void CustomerDetailView_ItemUpdated(Object sender, 
    DetailsViewUpdatedEventArgs e)
  {
  
    // Create a dictionary that contains the key fields and values using
    // the AllValues method of the DataKey object contained in the DataKey
 
    // property.
    IOrderedDictionary keyList = CustomerDetailView.DataKey.Values;

    // Get the ArrayList objects that represent the key fields and values.
    ArrayList keys = (ArrayList)keyList.Keys;
    ArrayList values = (ArrayList)keyList.Values;

    // Get the key field and value for the current record. 
    String keyField = keys[0].ToString();
    String keyValue = values[0].ToString();
    
    // Log the update operation using the key field and value.
    LogUpdate(keyField, keyValue);

  }

  void LogUpdate(String keyField, String keyValue)
  {
    // Insert code to log the update operation.
  }

</script>

<html>
  <body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView DataKey Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          autogenerateeditbutton="true" 
          allowpaging="true"
          onitemupdated="CustomerDetailView_ItemUpdated" 
          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]"
          UpdateCommand="UPDATE [Customers] SET 
            [CompanyName] = @CompanyName, 
            [Address] = @Address, [City] = @City,
            [PostalCode] = @PostalCode, [Country] = @Country
            WHERE [CustomerID] = @CustomerID">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DetailsView クラス
DetailsView メンバ
System.Web.UI.WebControls 名前空間
DataKey クラス
DataKeyNames
SelectedValue


このページでは「.NET Framework クラス ライブラリ リファレンス」からDetailsView.DataKey プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDetailsView.DataKey プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDetailsView.DataKey プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

「DetailsView.DataKey プロパティ」の関連用語

DetailsView.DataKey プロパティのお隣キーワード
検索ランキング

   

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



DetailsView.DataKey プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS