DataKey.Value プロパティ
アセンブリ: System.Web (system.web.dll 内)


Item プロパティまたは Values プロパティを使用して DataKey オブジェクトからキー フィールドの値を取得する代わりに、Value プロパティをショートカットとして使用して、DataKey オブジェクト内のインデックス 0 にあるキー フィールドの値を確認できます。このプロパティは、通常、レコードにキー フィールドが 1 つしかない場合に、そのレコードのキー フィールドの値を確認するために使用されます。
![]() |
---|
DataKey オブジェクトにキー フィールドが格納されていない場合、null 参照 (Visual Basic では Nothing) が返されます。 |

Value プロパティを使用してレコードの主キーの値を確認するコード例を次に示します。
<%@ 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDataKey.Value プロパティを検索する場合は、下記のリンクをクリックしてください。

- DataKey.Value プロパティのページへのリンク