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

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

FormView.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 FormView
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 オブジェクト

解説解説

DataKeyNames プロパティ設定されている場合、FormView コントロールは、現在のレコードDataKeyNames プロパティリストされているフィールド (複数可) のキーと値のペア格納する DataKey オブジェクト自動的に作成します。この DataKey オブジェクト取得するには、DataKey プロパティ使用します。このプロパティは、通常DataKeyNames プロパティ指定されているフィールドキーと、それらに対応する値を取得するために使用されます。

メモメモ

より簡単な方法として、SelectedValue プロパティ使用してDataKeyNames プロパティリストされている最初キー フィールドの値を確認することもできます

使用例使用例

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

<%@ Page language="VB" %>

<script runat="server">
  
  Sub EmployeeFormView_ItemCreated(ByVal sender
 As Object, ByVal e As
 EventArgs)
  
    Dim key As DataKey = EmployeeFormView.DataKey
    MessageLabel.Text = "The key value is " &
 key.Value.ToString() & "."
  
  End Sub
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>FormView DataKey Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        onitemcreated="EmployeeFormView_ItemCreated"
  
        runat="server">
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>'
 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName")
 %>&nbsp;<%# Eval("LastName") %></h3>
      
                <%# Eval("Title") %>       
 
              </td>
            </tr>
          </table>
        
        </itemtemplate>
        
      </asp:formview>
      
      <br/><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="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName],
 [Title], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
            
    </form>
  </body>
</html>

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

<script runat="server">
  
  void EmployeeFormView_ItemCreated(Object sender, EventArgs e)
  {
    DataKey key = EmployeeFormView.DataKey;
    MessageLabel.Text = "The key value is " + key.Value.ToString() + ".";
  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>FormView DataKey Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        onitemcreated="EmployeeFormView_ItemCreated"  
        runat="server">
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %>&nbsp;<%#
 Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
                  
      </asp:formview>
      
      <br/><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="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title],
 [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
            
    </form>
  </body>
</html>

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



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS