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


SelectedValue プロパティを使用して、現在のレコードのデータ キー値を確認します。レコードのデータ キーを表す実際の System.Web.UI.WebControls.DataKey オブジェクトを取得するには、DataKey プロパティを使用します。
このプロパティは、ControlParameter オブジェクトが実行時にバインドする既定のプロパティです。詳細については、「ControlValuePropertyAttribute」、「ControlParameter」、および「データ ソース コントロールとパラメータの使用」を参照してください。

SelectedValue プロパティを使用して、現在のレコードのデータ キー値を確認する方法のコード例を次に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub CustomerDetailView_ItemUpdated(ByVal sender As Object, ByVal e As DetailsViewUpdatedEventArgs) ' Log the update operation using the key value contained ' in the SelectedValue property. Dim keyValue As String = CustomerDetailView.SelectedValue.ToString() LogUpdate(keyValue) End Sub Sub LogUpdate(ByVal keyValue As String) ' Insert code to log the update operation. End Sub </script> <html> <body> <form id="Form1" runat="server"> <h3> DetailsView SelectedValue Example</h3> <asp:DetailsView ID="CustomerDetailView" DataSourceID="DetailsViewSource" DataKeyNames="CustomerID" AutoGenerateRows="true" AutoGenerateEditButton="true" AllowPaging="true" OnItemUpdated="CustomerDetailView_ItemUpdated" runat="server"> <FieldHeaderStyle 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) { // Log the update operation using the key value contained // in the SelectedValue property. String keyValue = CustomerDetailView.SelectedValue.ToString(); LogUpdate(keyValue); } void LogUpdate(String keyValue) { // Insert code to log the update operation. } </script> <html> <body> <form id="Form1" runat="server"> <h3>DetailsView SelectedValue Example</h3> <asp:detailsview id="CustomerDetailView" datasourceid="DetailsViewSource" datakeynames="CustomerID" autogeneraterows="true" autogenerateeditbutton="true" allowpaging="true" onitemupdated="CustomerDetailView_ItemUpdated" runat="server"> <fieldheaderstyle 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>

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に収録されているすべての辞書からDetailsView.SelectedValue プロパティを検索する場合は、下記のリンクをクリックしてください。

- DetailsView.SelectedValue プロパティのページへのリンク