DetailsView.SelectedValue Property
Gets the data key value of the current record in a DetailsView control.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Use the SelectedValue property to determine the data key value for the current record. To retrieve the actual System.Web.UI.WebControls.DataKey object that represents the data key for the record, use the DataKey property.
This property is the default property that a ControlParameter object binds to at run time. For more information, see ControlValuePropertyAttribute, ControlParameter, and Using Parameters with Data Source Controls for Filtering.
The following code example demonstrates how to use the SelectedValue property to determine the data key value for the current record.
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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 xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title> DetailsView SelectedValue Example</title> </head> <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 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.