다음을 통해 공유


DetailsView.SelectedValue 속성

정의

DetailsView 컨트롤에서 현재 레코드의 데이터 키 값을 가져옵니다.

public:
 property System::Object ^ SelectedValue { System::Object ^ get(); };
[System.ComponentModel.Browsable(false)]
public object SelectedValue { get; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectedValue : obj
Public ReadOnly Property SelectedValue As Object

속성 값

DetailsView 컨트롤의 현재 레코드에 대한 데이터 키 값입니다.

특성

예제

다음 코드 예제를 사용 SelectedValue 하는 방법에 설명 합니다 현재 레코드에 대 한 데이터 키 값을 확인 하는 속성입니다.


<%@ 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 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 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>

<%@ 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>

설명

사용 된 SelectedValue 현재 레코드에 대 한 데이터 키 값을 결정 하는 속성입니다. 레코드의 데이터 키를 나타내는 실제 System.Web.UI.WebControls.DataKey 개체를 검색하려면 속성을 사용합니다 DataKey .

이 속성은 기본 속성은는 ControlParameter 개체 런타임에 바인딩됩니다. 자세한 내용은 ControlValuePropertyAttribute, ControlParameter, 및 필터링에 대 한 데이터 소스 컨트롤을 사용 하 여 매개 변수를 사용 하 여입니다.

적용 대상

추가 정보