Share via


DataKey.Item[] プロパティ

定義

DataKey オブジェクトからキー フィールドの値を取得します。

オーバーロード

Item[Int32]

DataKey オブジェクト内の指定したインデックス位置にあるキー フィールドの値を取得します。

Item[String]

指定したフィールド名を持つキー フィールドの値を DataKey オブジェクトから取得します。

Item[Int32]

DataKey オブジェクト内の指定したインデックス位置にあるキー フィールドの値を取得します。

public:
 virtual property System::Object ^ default[int] { System::Object ^ get(int index); };
public virtual object this[int index] { get; }
member this.Item(int) : obj
Default Public Overridable ReadOnly Property Item(index As Integer) As Object

パラメーター

index
Int32

キー フィールドの値を取得する、0 から始まるインデックス。

プロパティ値

指定したインデックス位置にあるキー フィールドの値。

次のコード例では、 プロパティを使用して、オブジェクト内の Item[Int32] 特定のインデックスからキー フィールド値を取得する方法を DataKey 示します。


<%@ 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 CustomerDetailsView_DataBound(Object sender, EventArgs e)
  {

    // Get the value of the key field at index 2 in the DataKey object.
    String value = CustomerDetailsView.DataKey[2].ToString();

    // Display the value of the key field.
    MessageLabel.Text = "The value of the PostalCode key field is " + value +
      ".";

  }
  
</script>

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

  <head runat="server">
    <title>DataKey Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataKey Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          datakeynames="CustomerID, CompanyName, PostalCode"  
          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>

<%@ Page language="VB" autoeventwireup="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

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

    ' Get the value of the key field at index 2 in the DataKey object.
    Dim value As String = CustomerDetailsView.DataKey(2).ToString()

    ' Display the value of the key field.
    MessageLabel.Text = "The value of the PostalCode key field is " & value & _
      "."

  End Sub
  
</script>

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

  <head runat="server">
    <title>DataKey Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataKey Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          datakeynames="CustomerID, CompanyName, PostalCode"  
          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>

注釈

オブジェクト内の Item[Int32] 指定したインデックスにあるキー フィールドの値を取得するには、 プロパティを DataKey 使用します。

注意

または、 プロパティを Item[String] 使用して、フィールド名でキー フィールド値を取得することもできます。

こちらもご覧ください

適用対象

Item[String]

指定したフィールド名を持つキー フィールドの値を DataKey オブジェクトから取得します。

public:
 virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ name); };
public virtual object this[string name] { get; }
member this.Item(string) : obj
Default Public Overridable ReadOnly Property Item(name As String) As Object

パラメーター

name
String

キー フィールドの値を取得するキー フィールドの名前。

プロパティ値

指定したフィールド名を持つキー フィールドの値。

次のコード例では、 プロパティを使用して、オブジェクト内の Item[String] 特定のインデックスからキー フィールド値を取得する方法を DataKey 示します。


<%@ 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 CustomerDetailsView_DataBound(Object sender, EventArgs e)
  {

    // Get the value of the PostalCode key field.
    String value = CustomerDetailsView.DataKey["PostalCode"].ToString();

    // Display the value of the key field.
    MessageLabel.Text = "The value of the PostalCode key field is " + value +
      ".";

  }
  
</script>

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

  <head runat="server">
    <title>DataKey Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DataKey Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          datakeynames="CustomerID, CompanyName, PostalCode"  
          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>

<%@ Page language="VB" autoeventwireup="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

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

    ' Get the value of the PostalCode key field.
    Dim value As String = CustomerDetailsView.DataKey("PostalCode").ToString()

    ' Display the value of the key field.
    MessageLabel.Text = "The value of the PostalCode key field is " & value & _
      "."

  End Sub
  
</script>

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

  <head runat="server">
    <title>DataKey Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataKey Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          datakeynames="CustomerID, CompanyName, PostalCode"  
          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>

注釈

指定した Item[String] キー フィールドの値を オブジェクトから取得するには、 プロパティを DataKey 使用します。

注意

代わりに、 プロパティを Item[Int32] 使用して、インデックスによってキー フィールド値を取得することもできます。

こちらもご覧ください

適用対象