DetailsView 類別

定義

從資料表的資料來源顯示單一資料錄的值,其中每個資料列都代表資料錄的欄位。 DetailsView 控制項可讓您編輯、刪除及插入記錄。

public ref class DetailsView : System::Web::UI::WebControls::CompositeDataBoundControl, System::Web::UI::ICallbackEventHandler, System::Web::UI::IDataItemContainer, System::Web::UI::IPostBackEventHandler, System::Web::UI::WebControls::ICallbackContainer, System::Web::UI::WebControls::IPostBackContainer
public ref class DetailsView : System::Web::UI::WebControls::CompositeDataBoundControl, System::Web::UI::ICallbackEventHandler, System::Web::UI::IDataItemContainer, System::Web::UI::IPostBackEventHandler, System::Web::UI::WebControls::ICallbackContainer, System::Web::UI::WebControls::IDataBoundItemControl, System::Web::UI::WebControls::IFieldControl, System::Web::UI::WebControls::IPostBackContainer
[System.Web.UI.ControlValueProperty("SelectedValue")]
public class DetailsView : System.Web.UI.WebControls.CompositeDataBoundControl, System.Web.UI.ICallbackEventHandler, System.Web.UI.IDataItemContainer, System.Web.UI.IPostBackEventHandler, System.Web.UI.WebControls.ICallbackContainer, System.Web.UI.WebControls.IPostBackContainer
[System.Web.UI.ControlValueProperty("SelectedValue")]
public class DetailsView : System.Web.UI.WebControls.CompositeDataBoundControl, System.Web.UI.ICallbackEventHandler, System.Web.UI.IDataItemContainer, System.Web.UI.IPostBackEventHandler, System.Web.UI.WebControls.ICallbackContainer, System.Web.UI.WebControls.IDataBoundItemControl, System.Web.UI.WebControls.IFieldControl, System.Web.UI.WebControls.IPostBackContainer
[<System.Web.UI.ControlValueProperty("SelectedValue")>]
type DetailsView = class
    inherit CompositeDataBoundControl
    interface IDataItemContainer
    interface INamingContainer
    interface ICallbackContainer
    interface ICallbackEventHandler
    interface IPostBackEventHandler
    interface IPostBackContainer
[<System.Web.UI.ControlValueProperty("SelectedValue")>]
type DetailsView = class
    inherit CompositeDataBoundControl
    interface IDataItemContainer
    interface INamingContainer
    interface ICallbackContainer
    interface ICallbackEventHandler
    interface IPostBackEventHandler
    interface IPostBackContainer
    interface IDataBoundItemControl
    interface IDataBoundControl
    interface IFieldControl
Public Class DetailsView
Inherits CompositeDataBoundControl
Implements ICallbackContainer, ICallbackEventHandler, IDataItemContainer, IPostBackContainer, IPostBackEventHandler
Public Class DetailsView
Inherits CompositeDataBoundControl
Implements ICallbackContainer, ICallbackEventHandler, IDataBoundItemControl, IDataItemContainer, IFieldControl, IPostBackContainer, IPostBackEventHandler
繼承
屬性
實作

範例

下列程式碼範例示範如何使用 DetailsView 搭配控制項搭配 GridView 使用控制項,以取得簡單的主要詳細資料案例。 它會顯示控制項中 GridView 選取之專案的詳細資料。

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table>
        <tr>
          <td>
            <asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" DataSourceID="Customers"
              DataKeyNames="CustomerID">
              <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              </Columns>
            </asp:GridView>
          </td>
          <td valign="top">
            <asp:DetailsView ID="DetailsView1" runat="server" 
              AutoGenerateRows="True" DataKeyNames="CustomerID"
              DataSourceID="Details" Height="50px" Width="301px">
            </asp:DetailsView>
          </td>
        </tr>
      </table>
        
      <asp:SqlDataSource ID="Details" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = @CustomerID)">
        <SelectParameters>
          <asp:ControlParameter ControlID="GridView1" Name="CustomerID" 
            PropertyName="SelectedValue"
            Type="String" />
        </SelectParameters>
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="Customers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] FROM [Customers]">
      </asp:SqlDataSource>
    </div>
  </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table>
        <tr>
          <td>
            <asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" DataSourceID="Customers"
              DataKeyNames="CustomerID">
              <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              </Columns>
            </asp:GridView>
          </td>
          <td valign="top">
            <asp:DetailsView ID="DetailsView1" runat="server" 
              AutoGenerateRows="True" DataKeyNames="CustomerID"
              DataSourceID="Details" Height="50px" Width="301px">
            </asp:DetailsView>
          </td>
        </tr>
      </table>
        
      <asp:SqlDataSource ID="Details" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = @CustomerID)">
        <SelectParameters>
          <asp:ControlParameter ControlID="GridView1" Name="CustomerID" 
            PropertyName="SelectedValue"
            Type="String" />
        </SelectParameters>
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="Customers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] FROM [Customers]">
      </asp:SqlDataSource>
    </div>
  </form>
</body>
</html>

下列程式碼範例示範如何使用 DetailsView 控制項來新增、刪除和編輯記錄。


<%@ 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 CustomerDetail_ItemInserted(object sender, 
    DetailsViewInsertedEventArgs e)
  {
    // Refresh the GridView control after a new record is inserted 
    // in the DetailsView control.
    CustomersView.DataBind();
  }

  void CustomerDetail_ItemInserting(object sender, 
    DetailsViewInsertEventArgs e)
  {
    // Iterate though the values entered by the user and HTML encode 
    // the values. This helps prevent malicious values from being 
    // stored in the data source.
    for (int i = 0; i < e.Values.Count; i++)
    {
      if (e.Values[i] != null)
      {
        e.Values[i] = Server.HtmlEncode(e.Values[i].ToString());
      }
    }
  }

  void CustomerDetail_ItemUpdated(object sender, 
    DetailsViewUpdatedEventArgs e)
  {
    // Refresh the GridView control after a new record is updated 
    // in the DetailsView control.
    CustomersView.DataBind();
  }

  void CustomerDetail_ItemUpdating(object sender, 
    DetailsViewUpdateEventArgs e)
  {
    // Iterate though the values entered by the user and HTML encode 
    // the values. This helps prevent malicious values from being 
    // stored in the data source.
    for (int i = 0; i < e.NewValues.Count; i++)
    {
      if (e.NewValues[i] != null)
      {
        e.NewValues[i] = Server.HtmlEncode(e.NewValues[i].ToString());
      }
    }
  }

  void CustomerDetail_ItemDeleted(object sender, 
    DetailsViewDeletedEventArgs e)
  {
    // Refresh the GridView control after a new record is updated 
    // in the DetailsView control.
    CustomersView.DataBind();
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>
      DetailsView Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <h3>
      DetailsView Example</h3>
    <table cellspacing="10">
      <tr>
        <td>
          <!-- Use a GridView control in combination with      -->
          <!-- a DetailsView control to display master-detail  -->
          <!-- information. When the user selects a store from -->
          <!-- GridView control, the customers//s detailed     -->
          <!-- information is displayed in the DetailsView     -->
          <!-- control.                                        -->
          <asp:GridView ID="CustomersView" DataSourceID="Customers" 
            AutoGenerateColumns="False"
            DataKeyNames="CustomerID" runat="server">
            <HeaderStyle BackColor="Blue" ForeColor="White" />
            <Columns>
              <asp:CommandField ShowSelectButton="True" />
              <asp:BoundField DataField="ContactName" 
                HeaderText="ContactName" />
              <asp:BoundField DataField="CompanyName" 
                HeaderText="CompanyName" />
            </Columns>
          </asp:GridView>
        </td>
        <td valign="top">
          <asp:DetailsView ID="CustomerDetail" 
            DataSourceID="Details" AutoGenerateRows="false"
            AutoGenerateInsertButton="true" 
            AutoGenerateEditButton="true" 
            AutoGenerateDeleteButton="true"
            EmptyDataText="No records." 
            DataKeyNames="CustomerID" GridLines="Both" 
            OnItemInserted="CustomerDetail_ItemInserted"
            OnItemInserting="CustomerDetail_ItemInserting" 
            OnItemUpdated="CustomerDetail_ItemUpdated"
            OnItemUpdating="CustomerDetail_ItemUpdating" 
            OnItemDeleted="CustomerDetail_ItemDeleted"
            runat="server">
            <HeaderStyle BackColor="Navy" ForeColor="White" />
            <RowStyle BackColor="White" />
            <AlternatingRowStyle BackColor="LightGray" />
            <EditRowStyle BackColor="LightCyan" />
            <Fields>
              <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" />
              <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
              <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
              <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              <asp:BoundField DataField="Address" HeaderText="Address" />
              <asp:BoundField DataField="City" HeaderText="City" />
              <asp:BoundField DataField="Region" HeaderText="Region" />
              <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
              <asp:BoundField DataField="Country" HeaderText="Country" />
              <asp:BoundField DataField="Phone" HeaderText="Phone" />
              <asp:BoundField DataField="Fax" HeaderText="Fax" />
            </Fields>
          </asp:DetailsView>
        </td>
      </tr>
    </table>
    <!-- This example uses Microsoft SQL Server and connects -->
    <!-- to the Northwind sample database.                   -->
    <!-- It is strongly recommended that each data-bound     -->
    <!-- control uses a separate data source control.        -->
    <asp:SqlDataSource ID="Customers" runat="server" 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] 
        FROM [Customers]">
    </asp:SqlDataSource>
    <!-- Add a filter to the data source control for the     -->
    <!-- DetailsView control to display the details of the   -->
    <!-- store selected in the GridView control.             -->
    <asp:SqlDataSource ID="Details" 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      runat="server" 
      SelectCommand="SELECT * FROM [Customers] 
        WHERE ([CustomerID] = @CustomerID)"
      DeleteCommand="DELETE FROM [Customers] 
        WHERE [CustomerID] = @CustomerID"
      InsertCommand="INSERT INTO [Customers] ([CustomerID], 
        [CompanyName], [ContactName], [ContactTitle], [Address], 
        [City], [Region], [PostalCode], [Country], [Phone], [Fax]) 
        VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, 
        @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax)"
      UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, 
        [ContactName] = @ContactName, [ContactTitle] = @ContactTitle, 
        [Address] = @Address, [City] = @City, [Region] = @Region, 
        [PostalCode] = @PostalCode, [Country] = @Country, 
        [Phone] = @Phone, [Fax] = @Fax 
        WHERE [CustomerID] = @CustomerID">
      <SelectParameters>
        <asp:ControlParameter ControlID="CustomersView" 
          Name="CustomerID" PropertyName="SelectedValue"
          Type="String" />
      </SelectParameters>
      <DeleteParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
      </DeleteParameters>
      <UpdateParameters>
        <asp:Parameter Name="CompanyName" Type="String" />
        <asp:Parameter Name="ContactName" Type="String" />
        <asp:Parameter Name="ContactTitle" Type="String" />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="Region" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:Parameter Name="Country" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="Fax" Type="String" />
        <asp:Parameter Name="CustomerID" Type="String" />
      </UpdateParameters>
      <InsertParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
        <asp:Parameter Name="CompanyName" Type="String" />
        <asp:Parameter Name="ContactName" Type="String" />
        <asp:Parameter Name="ContactTitle" Type="String" />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="Region" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:Parameter Name="Country" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="Fax" Type="String" />
      </InsertParameters>
    </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 CustomerDetail_ItemInserted(ByVal sender As Object, _
    ByVal e As DetailsViewInsertedEventArgs)
    ' Refresh the GridView control after a new record is inserted in 
    ' the DetailsView control.
    CustomersView.DataBind()
  End Sub
  
  Sub CustomerDetail_ItemInserting(ByVal sender As Object, _
    ByVal e As DetailsViewInsertEventArgs)
    ' Iterate though the values entered by the user and HTML encode 
    ' the values. This helps prevent malicious values from being 
    ' stored in the data source.
    For i As Integer = 0 To e.Values.Count - 1
      If e.Values(i) IsNot Nothing Then
        e.Values(i) = Server.HtmlEncode(e.Values(i).ToString())
      End If
    Next
  End Sub
  
  Sub CustomerDetail_ItemUpdated(ByVal sender As Object, _
    ByVal e As DetailsViewUpdatedEventArgs)
    ' Refresh the GridView control after a new record is updated 
    ' in the DetailsView control.
    CustomersView.DataBind()
  End Sub
  
  Sub CustomerDetail_ItemUpdating(ByVal sender As Object, _
    ByVal e As DetailsViewUpdateEventArgs)
    ' Iterate though the values entered by the user and HTML encode 
    ' the values. This helps prevent malicious values from being 
    ' stored in the data source.
    For i As Integer = 0 To e.NewValues.Count - 1
      If e.NewValues(i) IsNot Nothing Then
        e.NewValues(i) = Server.HtmlEncode(e.NewValues(i).ToString())
      End If
    Next
  End Sub
  
  Sub CustomerDetail_ItemDeleted(ByVal sender As Object, _
    ByVal e As DetailsViewDeletedEventArgs)
    ' Refresh the GridView control after a new record is updated 
    ' in the DetailsView control.
    CustomersView.DataBind()
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>DetailsView Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <h3>DetailsView Example</h3>
    <table cellspacing="10">
      <tr>
        <td>
          <!-- Use a GridView control in combination with      -->
          <!-- a DetailsView control to display master-detail  -->
          <!-- information. When the user selects a store from -->
          <!-- GridView control, the customers's detailed      -->
          <!-- information is displayed in the DetailsView     -->
          <!-- control.                                        -->
          <asp:GridView ID="CustomersView" DataSourceID="Customers" 
            AutoGenerateColumns="False"
            DataKeyNames="CustomerID" runat="server">
            <HeaderStyle BackColor="Blue" ForeColor="White" />
            <Columns>
              <asp:CommandField ShowSelectButton="True" />
              <asp:BoundField DataField="ContactName" 
                HeaderText="ContactName" />
              <asp:BoundField DataField="CompanyName" 
                HeaderText="CompanyName" />
            </Columns>
          </asp:GridView>
        </td>
        <td valign="top">
          <asp:DetailsView ID="CustomerDetail" DataSourceID="Details" 
            AutoGenerateRows="false"
            AutoGenerateInsertButton="true" 
            AutoGenerateEditButton="true" 
            AutoGenerateDeleteButton="true"
            EmptyDataText="No records." 
            DataKeyNames="CustomerID" GridLines="Both" 
            OnItemInserted="CustomerDetail_ItemInserted"
            OnItemInserting="CustomerDetail_ItemInserting" 
            OnItemUpdated="CustomerDetail_ItemUpdated"
            OnItemUpdating="CustomerDetail_ItemUpdating" 
            OnItemDeleted="CustomerDetail_ItemDeleted"
            runat="server">
            <HeaderStyle BackColor="Navy" ForeColor="White" />
            <RowStyle BackColor="White" />
            <AlternatingRowStyle BackColor="LightGray" />
            <EditRowStyle BackColor="LightCyan" />
            <Fields>
              <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
                ReadOnly="True" />
              <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
              <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
              <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              <asp:BoundField DataField="Address" HeaderText="Address" />
              <asp:BoundField DataField="City" HeaderText="City" />
              <asp:BoundField DataField="Region" HeaderText="Region" />
              <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
              <asp:BoundField DataField="Country" HeaderText="Country" />
              <asp:BoundField DataField="Phone" HeaderText="Phone" />
              <asp:BoundField DataField="Fax" HeaderText="Fax" />
            </Fields>
          </asp:DetailsView>
        </td>
      </tr>
    </table>
    <!-- This example uses Microsoft SQL Server and connects -->
    <!-- to the Northwind sample database.                   -->
    <!-- It is strongly recommended that each data-bound     -->
    <!-- control uses a separate data source control.        -->
    <asp:SqlDataSource ID="Customers" runat="server" 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] 
        FROM [Customers]">
    </asp:SqlDataSource>
    <!-- Add a filter to the data source control for the     -->
    <!-- DetailsView control to display the details of the   -->
    <!-- store selected in the GridView control.             -->
    <asp:SqlDataSource ID="Details" 
      ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
      runat="server" 
      SelectCommand="SELECT * FROM [Customers] 
        WHERE ([CustomerID] = @CustomerID)"
      DeleteCommand="DELETE FROM [Customers] 
        WHERE [CustomerID] = @CustomerID"
      InsertCommand="INSERT INTO [Customers] ([CustomerID], 
        [CompanyName], [ContactName], [ContactTitle], [Address], 
        [City], [Region], [PostalCode], [Country], [Phone], [Fax]) 
        VALUES (@CustomerID, @CompanyName, @ContactName, 
        @ContactTitle, @Address, @City, @Region, @PostalCode, 
        @Country, @Phone, @Fax)"
      UpdateCommand="UPDATE [Customers] SET 
        [CompanyName] = @CompanyName, 
        [ContactName] = @ContactName, [ContactTitle] = @ContactTitle, 
        [Address] = @Address, [City] = @City, [Region] = @Region, 
        [PostalCode] = @PostalCode, [Country] = @Country, 
        [Phone] = @Phone, [Fax] = @Fax 
        WHERE [CustomerID] = @CustomerID">
      <SelectParameters>
        <asp:ControlParameter ControlID="CustomersView" 
          Name="CustomerID" PropertyName="SelectedValue"
          Type="String" />
      </SelectParameters>
      <DeleteParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
      </DeleteParameters>
      <UpdateParameters>
        <asp:Parameter Name="CompanyName" Type="String" />
        <asp:Parameter Name="ContactName" Type="String" />
        <asp:Parameter Name="ContactTitle" Type="String" />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="Region" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:Parameter Name="Country" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="Fax" Type="String" />
        <asp:Parameter Name="CustomerID" Type="String" />
      </UpdateParameters>
      <InsertParameters>
        <asp:Parameter Name="CustomerID" Type="String" />
        <asp:Parameter Name="CompanyName" Type="String" />
        <asp:Parameter Name="ContactName" Type="String" />
        <asp:Parameter Name="ContactTitle" Type="String" />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="Region" Type="String" />
        <asp:Parameter Name="PostalCode" Type="String" />
        <asp:Parameter Name="Country" Type="String" />
        <asp:Parameter Name="Phone" Type="String" />
        <asp:Parameter Name="Fax" Type="String" />
      </InsertParameters>
    </asp:SqlDataSource>
  </form>
</body>
</html>

下列程式碼範例示範如何以宣告方式將資料欄欄位新增至 DetailsView 控制項。

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <table cellspacing="10">
      <tr>
        <td>
          <!-- Use a GridView control in combination with      -->
          <!-- a DetailsView control to display master-detail  -->
          <!-- information. When the user selects a store from -->
          <!-- GridView control, the store's detailed          -->
          <!-- information is displayed in the DetailsView     -->
          <!-- control.                                        -->
          <asp:GridView ID="GridView1" runat="server" 
            DataSourceID="Customers" AutoGenerateColumns="False" 
            DataKeyNames="CustomerID">
            <Columns>
              <asp:CommandField ShowSelectButton="True" />
              <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
              <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
            </Columns>
          </asp:GridView>
        </td>
        <td valign="top">
          <asp:DetailsView ID="DetailsView" runat="server"
            DataSourceID="Details" AutoGenerateRows="false"
            DataKeyNames="CustomerID" >
            <HeaderStyle BackColor="Navy" ForeColor="White" />
            <Fields>
              <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
                ReadOnly="True" />
              <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
              <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
              <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              <asp:BoundField DataField="City" HeaderText="City" />
              <asp:BoundField DataField="Region" HeaderText="Region" />
              <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
              <asp:BoundField DataField="Country" HeaderText="Country" />
            </Fields>
          </asp:DetailsView>
        </td>
      </tr>
    </table>
    <!-- This example uses Microsoft SQL Server and connects -->
    <!-- to the Northwind sample database.                        -->
    <!-- It is strongly recommended that each data-bound     -->
    <!-- control uses a separate data source control.        -->
    <asp:SqlDataSource ID="Customers" runat="server" 
      ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] FROM [Customers]">
    </asp:SqlDataSource>
    <!-- Add a filter to the data source control for the     -->
    <!-- DetailsView control to display the details of the   -->
    <!-- store selected in the GridView control.             -->
    <asp:SqlDataSource ID="Details" runat="server" 
      ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = @CustomerID)">
      <SelectParameters>
        <asp:ControlParameter ControlID="GridView1" Name="CustomerID" 
          PropertyName="SelectedValue"
          Type="String" />
      </SelectParameters>
    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <table cellspacing="10">
      <tr>
        <td>
          <!-- Use a GridView control in combination with      -->
          <!-- a DetailsView control to display master-detail  -->
          <!-- information. When the user selects a store from -->
          <!-- GridView control, the store's detailed          -->
          <!-- information is displayed in the DetailsView     -->
          <!-- control.                                        -->
          <asp:GridView ID="GridView1" runat="server" 
            DataSourceID="Customers" AutoGenerateColumns="False" 
            DataKeyNames="CustomerID">
            <Columns>
              <asp:CommandField ShowSelectButton="True" />
              <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
              <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
            </Columns>
          </asp:GridView>
        </td>
        <td valign="top">
          <asp:DetailsView ID="DetailsView" runat="server"
            DataSourceID="Details" AutoGenerateRows="false"
            DataKeyNames="CustomerID" >
            <HeaderStyle BackColor="Navy" ForeColor="White" />
            <Fields>
              <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
                ReadOnly="True" />
              <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
              <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
              <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              <asp:BoundField DataField="City" HeaderText="City" />
              <asp:BoundField DataField="Region" HeaderText="Region" />
              <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
              <asp:BoundField DataField="Country" HeaderText="Country" />
            </Fields>
          </asp:DetailsView>
        </td>
      </tr>
    </table>
    <!-- This example uses Microsoft SQL Server and connects -->
    <!-- to the Northwind sample database.                        -->
    <!-- It is strongly recommended that each data-bound     -->
    <!-- control uses a separate data source control.        -->
    <asp:SqlDataSource ID="Customers" runat="server" 
      ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] FROM [Customers]">
    </asp:SqlDataSource>
    <!-- Add a filter to the data source control for the     -->
    <!-- DetailsView control to display the details of the   -->
    <!-- store selected in the GridView control.             -->
    <asp:SqlDataSource ID="Details" runat="server" 
      ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
      SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = @CustomerID)">
      <SelectParameters>
        <asp:ControlParameter ControlID="GridView1" Name="CustomerID" 
          PropertyName="SelectedValue"
          Type="String" />
      </SelectParameters>
    </asp:SqlDataSource>
  </form>
</body>
</html>

備註

本主題內容:

簡介

控制項 DetailsView 可用來顯示資料表中資料來源的單一記錄,其中記錄的每個欄位都會顯示在資料表的資料列中。 它可與主要詳細資料案例的控制項搭配 GridView 使用。 控制項 DetailsView 支援下列功能:

  • 系結至資料來源控制項,例如 SqlDataSource

  • 內建插入功能。

  • 內建更新和刪除功能。

  • 內建分頁功能。

  • 以程式設計方式存取 DetailsView 物件模型,以動態設定屬性、處理事件等等。

  • 可透過主題和樣式自訂的外觀。

資料欄欄位

控制項中的每個 DetailsView 資料列都是藉由宣告欄位控制項來建立。 不同的資料欄欄位類型會決定 控制項中資料列的行為。 欄位控制項衍生自 DataControlField 。 下表列出可使用的不同資料欄欄位類型。

資料列欄位類型 描述
BoundField 將資料來源中的欄位值顯示為文字。
ButtonField 在 控制項中 DetailsView 顯示命令按鈕。 這可讓您顯示具有自訂按鈕控制項的資料列,例如 [新增] 或 [移除] 按鈕。
CheckBoxField 在 控制項中 DetailsView 顯示覆選框。 此資料欄欄位類型通常用來顯示具有布林值的欄位。
CommandField 顯示內建命令按鈕,以在 控制項中 DetailsView 執行編輯、插入或刪除作業。
HyperLinkField 將資料來源中的欄位值顯示為超連結。 此資料欄欄位類型可讓您將第二個欄位系結至超連結的 URL。
ImageField 在 控制項中 DetailsView 顯示影像。
TemplateField 根據指定的範本,顯示控制項中資料列的使用者 DetailsView 定義內容。 此資料欄欄位類型可讓您建立自訂資料欄欄位。

根據預設, AutoGenerateRows 屬性會設定為 true ,這會針對資料來源中可系結類型的每個欄位自動產生系結資料欄欄位物件。 有效的可系結型別為 StringDateTimeDecimalGuid 和一組基本類型。 然後,每個欄位都會以文字的形式顯示在資料列中,以每個欄位出現在資料來源中的順序。

自動產生資料列提供快速且簡單的方式,以在記錄中顯示每個欄位。 不過,若要使用 DetailsView 控制項的進階功能,您必須明確宣告要包含在 控制項中的資料 DetailsView 欄欄位。 若要宣告資料欄欄位,請先將 AutoGenerateRows 屬性設定為 false 。 接下來,在控制項的 DetailsView 開頭和結束記號之間新增開頭和結尾 <Fields> 標記。 最後,列出您想要在開頭和結尾 <Fields> 標記之間包含的資料欄欄位。 指定的資料欄欄位會依列出的順序新增至 Fields 集合。 集合 Fields 可讓您以程式設計方式管理 控制項中的資料 DetailsView 欄欄位。

注意

自動產生的資料欄欄位不會新增至 Fields 集合。

注意

明確宣告的資料欄欄位可以與自動產生的資料欄欄位一起顯示。 同時使用這兩個欄位時,會先轉譯明確宣告的資料欄欄位,後面接著自動產生的資料欄欄位。

系結至資料

控制項 DetailsView 可以系結至資料來源控制項 (,例如 SqlDataSource 控制項或 ObjectDataSource 控制項) ,或實作 System.Collections.IEnumerable 介面的任何資料來源集合,例如 System.Data.DataViewSystem.Collections.ArrayListSystem.Collections.Generic.List<T> 或其他集合類型。 使用下列其中一種方法,將 DetailsView 控制項系結至適當的資料來源類型:

如需資料系結的詳細資訊,請參閱 系結至資料庫

安全性

此控制項可用來顯示使用者輸入,其中可能包含惡意用戶端腳本。 在應用程式中顯示可執行檔腳本、SQL 語句或其他程式碼之前,請先檢查從用戶端傳送的任何資訊。 ASP.NET 提供輸入要求驗證功能,以封鎖使用者輸入中的腳本和 HTML。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。 也會提供驗證服務器控制項來評估使用者輸入。 如需詳細資訊,請參閱 驗證服務器控制項語法

資料作業

控制項 DetailsView 提供內建功能,可讓使用者透過控制項中的專案來更新、刪除、插入和分頁。 DetailsView當控制項系結至資料來源控制項時, DetailsView 控制項可以利用資料來源控制項的功能,並提供自動更新、刪除、插入和分頁功能。

注意

控制項 DetailsView 可為其他類型的資料來源提供更新、刪除、插入和分頁作業的支援;不過,您必須在適當的事件處理常式中提供這些作業的實作。 如需詳細資訊,請參閱ItemDeletingItemInsertingItemUpdating

控制項 DetailsView 可以分別將 、 AutoGenerateDeleteButton 或 屬性設定 AutoGenerateEditButtontrue ,以自動新增 CommandField 具有 [編輯]、[刪除] 或 AutoGenerateInsertButton [新增] 按鈕的資料欄欄位。 不同于 [刪除] 按鈕 (會立即刪除選取的記錄) 按一下 [編輯] 或 [新增] 按鈕時, DetailsView 控制項會分別進入編輯或插入模式。 在編輯模式中,[編輯] 按鈕會取代為 [更新] 和 [取消] 按鈕。 適用于欄位資料類型的輸入控制項 (,例如 TextBoxCheckBox 控制項) ,會顯示欄位的值以供使用者修改。 按一下 [更新] 按鈕會更新資料來源中的記錄,然後按一下 [取消] 按鈕會放棄任何變更。 同樣地,在插入模式中,[新增] 按鈕會取代為 [插入] 和 [取消] 按鈕,並顯示空白輸入控制項,讓使用者輸入新記錄的值。

注意

您也可以在 、 CommandFieldTemplateField 資料欄欄位中手動定義更新、刪除和插入命令按鈕 ButtonField 。 控制項 DetailsView 會辨識屬性設定為 「Edit」、「Update」、「Delete」、「New」、「Insert」 或 「Cancel」 的按鈕 CommandName ;不過,您仍然必須自行提供功能。 如需詳細資訊,請參閱ItemDeletingItemInsertingItemUpdating

控制項 DetailsView 提供分頁功能,讓使用者流覽至資料來源中的其他記錄。 啟用時,頁面導覽控制項會顯示在呼叫器資料列中。 若要啟用分頁,請將 AllowPaging 屬性設定為 true 。 您可以使用 和 PagerSettings 屬性來自訂 PagerStyle 呼叫器資料列。

自訂使用者介面

您可以為控制項的不同部分設定樣式屬性,以自訂控制項的外觀 DetailsView 。 下表列出您可以設定的樣式屬性。

Style 屬性 描述
AlternatingRowStyle 控制項中替代資料列的 DetailsView 樣式設定。 設定此屬性時,資料列會顯示在帶狀區中,在設定與 AlternatingRowStyle 設定之間 RowStyle 交替。
CommandRowStyle 包含內建命令按鈕之資料列的樣式設定。
EditRowStyle 控制項處於編輯模式時,資料列的 DetailsView 樣式設定。
EmptyDataRowStyle 當資料來源不包含任何記錄時,控制項中顯示的 DetailsView 空白資料列樣式設定。
FooterStyle 頁尾資料列的樣式設定。
HeaderStyle 標題列的樣式設定。
InsertRowStyle 控制項處於插入模式時 DetailsView ,資料列的樣式設定。
PagerStyle 呼叫器資料列的樣式設定。
RowStyle 控制項中資料列的 DetailsView 樣式設定。 AlternatingRowStyle同時設定 屬性時,資料列會顯示在設定與 AlternatingRowStyle 設定之間 RowStyle 交替。
FieldHeaderStyle 標頭資料行的樣式設定。

事件

控制項 DetailsView 提供數個您可以針對的事件進行程式設計。 這可讓您在事件發生時執行自訂常式。 下表列出 控制項所 DetailsView 支援的事件。 控制項 DetailsView 也會從其基類繼承這些事件: DataBinding 、、 DataBoundDisposedInitLoadPreRenderRender

事件 描述
ItemCommand 按一下 DetailsView 控制項中的按鈕時會發生這個事件。
ItemCreated 發生于 控制項中 DetailsView 建立所有 DetailsViewRow 物件之後。 此事件通常用於在顯示記錄之前修改記錄的值。
ItemDeleted 發生于按一下 [刪除] 按鈕時,但在控制項從資料來源中刪除記錄之後 DetailsView 。 此事件通常用於檢查刪除作業的結果。
ItemDeleting 發生于按一下 [刪除] 按鈕時,但在控制項從資料來源中刪除記錄之前 DetailsView 。 此事件通常用於取消刪除作業。
ItemInserted 發生于按一下 [插入] 按鈕時,但在控制項插入記錄之後 DetailsView 。 此事件通常用於檢查插入作業的結果。
ItemInserting 發生于按一下 [插入] 按鈕,但在控制項插入記錄之前 DetailsView 。 此事件通常用於取消插入作業。
ItemUpdated 發生于按一下 [更新] 按鈕,但在控制項更新資料列之後 DetailsView 。 此事件通常用於檢查更新作業的結果。
ItemUpdating 發生于按一下 [更新] 按鈕,但在控制項更新記錄之前 DetailsView 。 此事件通常用於取消更新作業。
ModeChanged 發生 DetailsView 于控制項變更模式 (編輯、插入或唯讀模式) 之後。 當控制項變更模式時 DetailsView ,通常會使用此事件來執行工作。
ModeChanging 在控制項變更模式之前 DetailsView 發生, (編輯、插入或唯讀模式) 。 此事件通常用於取消模式變更。
PageIndexChanged 按一下其中一個頁面巡覽區按鈕時發生 (但在 DetailsView 控制項處理分頁作業之後)。 當您需要在使用者巡覽至 控制項中的不同記錄之後執行工作時,通常會使用此事件。
PageIndexChanging 發生於按一下其中一個頁面巡覽區按鈕時,但是在 DetailsView 控制項處理分頁作業之前。 此事件通常用於取消分頁作業。

Accessibility

如需如何設定此控制項以產生符合協助工具標準的標記的相關資訊,請參閱 Visual Studio 中的協助工具,以及 ASP.NETASP.NET 控制項和協助工具

宣告式語法

<asp:DetailsView
    AccessKey="string"
    AllowPaging="True|False"
    AutoGenerateDeleteButton="True|False"
    AutoGenerateEditButton="True|False"
    AutoGenerateInsertButton="True|False"
    AutoGenerateRows="True|False"
    BackColor="color name|#dddddd"
    BackImageUrl="uri"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    Caption="string"
    CaptionAlign="NotSet|Top|Bottom|Left|Right"
    CellPadding="integer"
    CellSpacing="integer"
    CssClass="string"
    DataKeyNames="string"
    DataMember="string"
    DataSource="string"
    DataSourceID="string"
    DefaultMode="ReadOnly|Edit|Insert"
    EmptyDataText="string"
    Enabled="True|False"
    EnablePagingCallbacks="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    FooterText="string"
    ForeColor="color name|#dddddd"
    GridLines="None|Horizontal|Vertical|Both"
    HeaderText="string"
    Height="size"
    HorizontalAlign="NotSet|Left|Center|Right|Justify"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDataBound="DataBound event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnItemCommand="ItemCommand event handler"
    OnItemCreated="ItemCreated event handler"
    OnItemDeleted="ItemDeleted event handler"
    OnItemDeleting="ItemDeleting event handler"
    OnItemInserted="ItemInserted event handler"
    OnItemInserting="ItemInserting event handler"
    OnItemUpdated="ItemUpdated event handler"
    OnItemUpdating="ItemUpdating event handler"
    OnLoad="Load event handler"
    OnModeChanged="ModeChanged event handler"
    OnModeChanging="ModeChanging event handler"
    OnPageIndexChanged="PageIndexChanged event handler"
    OnPageIndexChanging="PageIndexChanging event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    PageIndex="integer"
    PagerSettings-FirstPageImageUrl="uri"
    PagerSettings-FirstPageText="string"
    PagerSettings-LastPageImageUrl="uri"
    PagerSettings-LastPageText="string"
    PagerSettings-Mode="NextPrevious|Numeric|NextPreviousFirstLast|NumericFirstLast"
    PagerSettings-NextPageImageUrl="uri"
    PagerSettings-NextPageText="string"
    PagerSettings-PageButtonCount="integer"
    PagerSettings-Position="Bottom|Top|TopAndBottom"
    PagerSettings-PreviousPageImageUrl="uri"
    PagerSettings-PreviousPageText="string"
    PagerSettings-Visible="True|False"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    ToolTip="string"
    Visible="True|False"
    Width="size"
>
        <AlternatingRowStyle />
        <CommandRowStyle />
        <EditRowStyle />
        <EmptyDataRowStyle />
        <EmptyDataTemplate>
            <!-- child controls -->
        </EmptyDataTemplate>
        <FieldHeaderStyle />
        <Fields>
                <asp:BoundField
                    AccessibleHeaderText="string"
                    ApplyFormatInEditMode="True|False"
                    ConvertEmptyStringToNull="True|False"
                    DataField="string"
                    DataFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    HtmlEncode="True|False"
                    InsertVisible="True|False"
                    NullDisplayText="string"
                    ReadOnly="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:BoundField>
                <asp:ButtonField
                    AccessibleHeaderText="string"
                    ButtonType="Button|Image|Link"
                    CausesValidation="True|False"
                    CommandName="string"
                    DataTextField="string"
                    DataTextFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    ImageUrl="uri"
                    InsertVisible="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Text="string"
                    ValidationGroup="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:ButtonField>
                <asp:CheckBoxField
                    AccessibleHeaderText="string"
                    DataField="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    ReadOnly="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Text="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:CheckBoxField>
                <asp:CommandField
                    AccessibleHeaderText="string"
                    ButtonType="Button|Image|Link"
                    CancelImageUrl="uri"
                    CancelText="string"
                    CausesValidation="True|False"
                    DeleteImageUrl="uri"
                    DeleteText="string"
                    EditImageUrl="uri"
                    EditText="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertImageUrl="uri"
                    InsertText="string"
                    InsertVisible="True|False"
                    NewImageUrl="uri"
                    NewText="string"
                    SelectImageUrl="uri"
                    SelectText="string"
                    ShowCancelButton="True|False"
                    ShowDeleteButton="True|False"
                    ShowEditButton="True|False"
                    ShowHeader="True|False"
                    ShowInsertButton="True|False"
                    ShowSelectButton="True|False"
                    SortExpression="string"
                    UpdateImageUrl="uri"
                    UpdateText="string"
                    ValidationGroup="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:CommandField>
                <asp:DynamicField
                    AccessibleHeaderText="string"
                    ApplyFormatInEditMode="True|False"
                    ConvertEmptyStringToNull="True|False"
                    DataField="string"
                    DataFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    HtmlEncode="True|False"
                    InsertVisible="True|False"
                    NullDisplayText="string"
                    ShowHeader="True|False"
                    UIHint="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:DynamicField>
                <asp:HyperLinkField
                    AccessibleHeaderText="string"
                    DataNavigateUrlFields="string"
                    DataNavigateUrlFormatString="string"
                    DataTextField="string"
                    DataTextFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    NavigateUrl="uri"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Target="string|_blank|_parent|_search|_self|_top"
                    Text="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:HyperLinkField>
                <asp:ImageField
                    AccessibleHeaderText="string"
                    AlternateText="string"
                    ConvertEmptyStringToNull="True|False"
                    DataAlternateTextField="string"
                    DataAlternateTextFormatString="string"
                    DataImageUrlField="string"
                    DataImageUrlFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    NullDisplayText="string"
                    NullImageUrl="uri"
                    ReadOnly="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:ImageField>
                <asp:TemplateField
                    AccessibleHeaderText="string"
                    ConvertEmptyStringToNull="True|False"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Visible="True|False"
>
                            <ControlStyle />
                            <FooterStyle />
                            <HeaderStyle />
                            <ItemStyle />
                        <AlternatingItemTemplate>
                            <!-- child controls -->
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <!-- child controls -->
                        </EditItemTemplate>
                        <FooterTemplate>
                            <!-- child controls -->
                        </FooterTemplate>
                        <HeaderTemplate>
                            <!-- child controls -->
                        </HeaderTemplate>
                        <InsertItemTemplate>
                            <!-- child controls -->
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <!-- child controls -->
                        </ItemTemplate>
                </asp:TemplateField>
        </Fields>
        <FooterStyle />
        <FooterTemplate>
            <!-- child controls -->
        </FooterTemplate>
        <HeaderStyle />
        <HeaderTemplate>
            <!-- child controls -->
        </HeaderTemplate>
        <InsertRowStyle />
        <PagerSettings
            FirstPageImageUrl="uri"
            FirstPageText="string"
            LastPageImageUrl="uri"
            LastPageText="string"
            Mode="NextPrevious|Numeric|NextPreviousFirstLast|
                NumericFirstLast"
            NextPageImageUrl="uri"
            NextPageText="string"
            OnPropertyChanged="PropertyChanged event handler"
            PageButtonCount="integer"
            Position="Bottom|Top|TopAndBottom"
            PreviousPageImageUrl="uri"
            PreviousPageText="string"
            Visible="True|False"
        />
        <PagerStyle />
        <PagerTemplate>
            <!-- child controls -->
        </PagerTemplate>
        <RowStyle        />
</asp:DetailsView>

建構函式

DetailsView()

初始化 DetailsView 類別的新執行個體。

屬性

AccessKey

取得或設定便捷鍵 (Access Key),可讓您快速巡覽至 Web 伺服器控制項。

(繼承來源 WebControl)
Adapter

針對控制項取得瀏覽器的特定配置器。

(繼承來源 Control)
AllowPaging

取得或設定值,指出是否啟用分頁功能。

AlternatingRowStyle

取得 TableItemStyle 物件的參考,這個物件可讓您設定 DetailsView 控制項中替代資料列的外觀。

AppRelativeTemplateSourceDirectory

取得或設定包含了此控制項之 PageUserControl 物件的相對應用程式虛擬目錄。

(繼承來源 Control)
Attributes

取得任意屬性 (Attribute) 的集合 (只供呈現),不與控制項上的屬性 (Property) 對應。

(繼承來源 WebControl)
AutoGenerateDeleteButton

取得或設定值,指出可刪除目前資料錄的內建控制項是否顯示於 DetailsView 控制項中。

AutoGenerateEditButton

取得或設定值,指出可編輯目前資料錄的內建控制項是否顯示於 DetailsView 控制項中。

AutoGenerateInsertButton

取得或設定值,指出可插入新資料錄的內建控制項是否顯示於 DetailsView 控制項中。

AutoGenerateRows

取得或設定值,指出資料來源中每個欄位的資料列欄位是否會自動產生並顯示於 DetailsView 控制項中。

BackColor

取得或設定 Web 伺服器控制項的背景色彩。

(繼承來源 WebControl)
BackImageUrl

取得或設定要顯示於 DetailsView 控制項背景之影像的 URL。

BindingContainer

取得包含了此控制項之資料繫結的控制項。

(繼承來源 Control)
BorderColor

取得或設定 Web 控制項的框線色彩。

(繼承來源 WebControl)
BorderStyle

取得或設定 Web 伺服器控制項的框線樣式。

(繼承來源 WebControl)
BorderWidth

取得或設定 Web 伺服器控制項的框線寬度。

(繼承來源 WebControl)
BottomPagerRow

取得 DetailsViewRow 物件,其表示 DetailsView 控制項中的底端頁面巡覽列。

Caption

取得或設定要在 DetailsView 控制項之 HTML 標題項目中呈現的文字。 這個屬性可讓協助技術裝置的使用者更容易存取控制項。

CaptionAlign

取得或設定 DetailsView 控制項中 HTML 標題項目的水平或垂直位置。 這個屬性可讓協助技術裝置的使用者更容易存取控制項。

CellPadding

取得或設定儲存格內容和其框線之間的間距。

CellSpacing

取得或設定儲存格之間的間距。

ChildControlsCreated

取得值,指出是否已經建立伺服器控制項的子控制項。

(繼承來源 Control)
ClientID

取得 ASP.NET 所產生之 HTML 標記的控制項識別碼。

(繼承來源 Control)
ClientIDMode

取得或設定用來產生 ClientID 屬性值的演算法。

(繼承來源 Control)
ClientIDSeparator

取得字元值,表示在 ClientID 屬性中所使用的分隔字元。

(繼承來源 Control)
CommandRowStyle

取得 TableItemStyle 物件的參考,這個物件可讓您設定 DetailsView 控制項中命令資料列的外觀。

Context

取得與目前 Web 要求的伺服器控制項關聯的 HttpContext 物件。

(繼承來源 Control)
Controls

取得複合資料繫結控制項內之子控制項的集合。

(繼承來源 CompositeDataBoundControl)
ControlStyle

取得 Web 伺服器控制項的樣式。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
ControlStyleCreated

取得值,指出 Style 物件是否已經為 ControlStyle 屬性建立。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
CssClass

取得或設定用戶端上 Web 伺服器控制項所呈現的階層式樣式表 (CSS)。

(繼承來源 WebControl)
CurrentMode

取得 DetailsView 控制項目前的資料輸入模式。

DataItem

取得繫結至 DetailsView 控制項的資料項目。

DataItemContainer

如果命名容器實作 IDataItemContainer,則取得命名容器的參考。

(繼承來源 Control)
DataItemCount

取得基礎資料來源中的項目數目。

DataItemIndex

取得項目的索引,此項目來自基礎資料來源,目前顯示在 DetailsView 控制項中。

DataKey

取得 DataKey 物件,表示所顯示資料錄的主索引鍵。

DataKeyNames

取得或設定陣列,陣列中包含資料來源的索引鍵欄位名稱。

DataKeysContainer

如果命名容器實作 IDataKeysControl,則取得命名容器的參考。

(繼承來源 Control)
DataMember

取得或設定資料繫結控制項繫結至的資料清單名稱 (如果資料來源包含多個不同資料項目清單)。

(繼承來源 DataBoundControl)
DataSource

取得或設定資料繫結控制項從中擷取其資料項目清單的物件。

(繼承來源 BaseDataBoundControl)
DataSourceID

取得或設定控制項的識別碼,資料繫結控制項會由此擷取其項目清單。

(繼承來源 DataBoundControl)
DataSourceObject

取得物件,這個物件會實作可提供物件資料內容之存取權的 IDataSource 介面。

(繼承來源 DataBoundControl)
DefaultMode

取得或設定 DetailsView 控制項的預設資料輸入模式。

DeleteMethod

取得或設定在頁面上控制項執行刪除作業時所呼叫的方法名稱。

DeleteMethod

為了刪除資料,取得或設定要呼叫的方法名稱。

(繼承來源 CompositeDataBoundControl)
DesignMode

取得值,指出控制項是否正用於設計介面上。

(繼承來源 Control)
EditRowStyle

取得 TableItemStyle 物件的參考,這個物件可以讓您設定當 DetailsView 控制項處於編輯模式時的資料列外觀。

EmptyDataRowStyle

取得 TableItemStyle 物件的參考,可以讓您設定當繫結至 DetailsView 控制項的資料來源不含任何資料錄時,顯示之空白資料列的外觀。

EmptyDataTemplate

取得或設定空白資料之使用者定義的內容,該資料列呈現於 DetailsView 控制項繫結至不包含任何資料錄的資料來源時。

EmptyDataText

取得或設定空白資料列中顯示的文字,該資料列呈現於 DetailsView 控制項繫結至不包含任何資料錄的資料來源時。

Enabled

取得或設定值,指出 Web 伺服器控制項是否啟用。

(繼承來源 WebControl)
EnableModelValidation

取得或設定值,這個值指出是否啟用資料模型驗證。

EnablePagingCallbacks

取得或設定值,指出是否在 DetailsView 控制項的分頁作業中使用用戶端回呼函式 (Callback Function)。

EnableTheming

取得或設定值,指出佈景主題是否套用至此控制項。

(繼承來源 WebControl)
EnableViewState

取得或設定值,該值表示伺服器控制項是否對要求的用戶端而言保持其檢視狀態,以及它包含的任何子控制項狀態。

(繼承來源 Control)
Events

取得控制項事件處理常式委派 (Delegate) 的清單。 這個屬性是唯讀的。

(繼承來源 Control)
FieldHeaderStyle

取得 TableItemStyle 物件的參考,這個物件可讓您設定 DetailsView 控制項中標頭資料行的外觀。

Fields

取得 DataControlField 物件的集合,表示 DetailsView 控制項中明確宣告的資料列欄位。

Font

取得與 Web 伺服器控制項關聯的字型屬性。

(繼承來源 WebControl)
FooterRow

取得 DetailsViewRow 物件,其表示 DetailsView 控制項中的頁尾資料列。

FooterStyle

取得 TableItemStyle 物件的參考,可以讓您設定 DetailsView 控制項中頁尾資料列的外觀。

FooterTemplate

取得或設定 DetailsView 控制項中,頁尾資料列的使用者定義內容。

FooterText

取得或設定顯示於 DetailsView 控制項頁尾資料列的文字。

ForeColor

取得或設定 Web 伺服器控制項的前景色彩 (通常是文字的色彩)。

(繼承來源 WebControl)
GridLines

取得或設定 DetailsView 控制項的格線樣式。

HasAttributes

取得值,指出控制項是否已經設定屬性。

(繼承來源 WebControl)
HasChildViewState

取得值,指出目前伺服器控制項的子控制項是否有任何已儲存的檢視狀態設定。

(繼承來源 Control)
HeaderRow

取得 DetailsViewRow 物件,表示 DetailsView 控制項中的標頭資料列。

HeaderStyle

取得 TableItemStyle 物件的參考,可以讓您設定 DetailsView 控制項中頁首資料列的外觀。

HeaderTemplate

取得或設定 DetailsView 控制項中,標頭資料列的使用者定義內容。

HeaderText

取得或設定顯示於 DetailsView 控制項中頁首資料列的文字。

Height

取得或設定 Web 伺服器控制項的高度。

(繼承來源 WebControl)
HorizontalAlign

取得或設定頁面上 DetailsView 控制項的水平對齊。

ID

取得或設定指派給伺服器控制項的程式設計識別項。

(繼承來源 Control)
IdSeparator

取得用來分隔控制項識別項的字元。

(繼承來源 Control)
Initialized

取得值,指出是否已初始化資料繫結控制項。

(繼承來源 BaseDataBoundControl)
InsertMethod

取得或設定在頁面上控制項執行插入作業時所呼叫的方法名稱。

InsertMethod

為了插入資料,取得或設定要呼叫的方法名稱。

(繼承來源 CompositeDataBoundControl)
InsertRowStyle

取得 TableItemStyle 物件的參考,這個物件可讓您在 DetailsView 控制項處於插入模式時,設定 DetailsView 控制項中資料列的外觀。

IsBoundUsingDataSourceID

取得值,指出是否已設定 DataSourceID 屬性。

(繼承來源 BaseDataBoundControl)
IsChildControlStateCleared

取得值,指出這個控制項中所包含的控制項是否有控制項狀態。

(繼承來源 Control)
IsDataBindingAutomatic

取得值,指出資料繫結是否為自動。

(繼承來源 BaseDataBoundControl)
IsEnabled

取得值,指出是否啟用控制項。

(繼承來源 WebControl)
IsTrackingViewState

取得值,指出伺服器控制項是否正在儲存檢視狀態的變更。

(繼承來源 Control)
IsUsingModelBinders

取得值,指出模型繫結是否正在使用。

(繼承來源 CompositeDataBoundControl)
IsViewStateEnabled

取得值,指出這個控制項是否已啟用檢視狀態。

(繼承來源 Control)
ItemType

取得或設定強型別資料繫結的資料項目型別名稱。

(繼承來源 DataBoundControl)
LoadViewStateByID

取得值,指出控制項是否依 ID (而不是索引) 參與載入其檢視狀態。

(繼承來源 Control)
NamingContainer

取得伺服器控制項命名容器的參考,其建立唯一命名空間,在具有相同 ID 屬性值的伺服器控制項之間作區別。

(繼承來源 Control)
Page

取得含有伺服器控制項的 Page 執行個體的參考。

(繼承來源 Control)
PageCount

取得資料來源中的資料錄數目。

PageIndex

取得或設定顯示資料錄的索引。

PagerSettings

取得 PagerSettings 物件的參考,可以讓您設定 DetailsView 控制項中頁面巡覽區按鈕的屬性。

PagerStyle

取得 TableItemStyle 物件的參考,可以讓您設定 DetailsView 控制項中頁面巡覽列的外觀。

PagerTemplate

取得或設定 DetailsView 控制項中頁面巡覽列的自訂內容。

Parent

在網頁控制階層架構中取得伺服器控制項之父控制項的參考。

(繼承來源 Control)
RenderingCompatibility

取得值,這個值會指定將與呈現 HTML 相容的 ASP.NET 版本。

(繼承來源 Control)
RequiresDataBinding

取得或設定值,指出是否應該呼叫 DataBind() 方法。

(繼承來源 BaseDataBoundControl)
Rows

取得 DetailsViewRow 物件的集合,其表示 DetailsView 控制項中的資料列。

RowsGenerator

取得或設定物件,這個物件會實作 IAutoFieldGenerator 介面,以便在檢視中自動填入資料列。

RowStyle

取得 TableItemStyle 物件的參考,這個物件可讓您設定 DetailsView 控制項中資料列的外觀。

SelectArguments

取得 DataSourceSelectArguments 物件,當從資料來源控制項擷取資料時資料繫結控制項會使用它。

(繼承來源 DataBoundControl)
SelectedValue

取得 DetailsView 控制項中目前資料錄的資料索引鍵值。

SelectMethod

為了讀取資料要呼叫的方法的名稱。

(繼承來源 DataBoundControl)
Site

當呈現在設計介面上時,取得裝載目前控制項之容器的資訊。

(繼承來源 Control)
SkinID

取得或設定要套用至控制項的面板。

(繼承來源 WebControl)
Style

取得文字屬性的集合,將呈現為 Web 伺服器控制項的外部標記上的樣式屬性。

(繼承來源 WebControl)
SupportsDisabledAttribute

取得值,這個值表示當控制項的 disabled 屬性為 IsEnabled 時,控制項是否應該將呈現之 HTML 項目的 false 屬性設為 "disabled"。

(繼承來源 BaseDataBoundControl)
TabIndex

取得或設定 Web 伺服器控制項的定位索引。

(繼承來源 WebControl)
TagKey

取得 DetailsView 控制項的 HtmlTextWriterTag 值。

TagName

取得控制項標記的名稱。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
TemplateControl

取得或設定包含了此控制項之樣板的參考。

(繼承來源 Control)
TemplateSourceDirectory

取得包含目前伺服器控制項的 PageUserControl 的虛擬目錄。

(繼承來源 Control)
ToolTip

取得或設定當滑鼠指標停留在 Web 伺服器控制項時顯示的文字。

(繼承來源 WebControl)
TopPagerRow

取得 DetailsViewRow 物件,其表示 DetailsView 控制項中的頂端頁面巡覽列。

UniqueID

取得伺服器控制項唯一的、符合階層架構的識別項。

(繼承來源 Control)
UpdateMethod

取得或設定在頁面上控制項執行更新作業時所呼叫的方法名稱。

UpdateMethod

為了更新資料,取得或設定要呼叫的方法名稱。

(繼承來源 CompositeDataBoundControl)
ValidateRequestMode

取得或設定值,指出控制項是否對來自瀏覽器的用戶端輸入檢查潛在的危險值。

(繼承來源 Control)
ViewState

取得狀態資訊的字典,允許您在相同網頁的多個要求之間,儲存和還原伺服器控制項的檢視狀態。

(繼承來源 Control)
ViewStateIgnoresCase

取得值,指出 StateBag 物件是否不區分大小寫。

(繼承來源 Control)
ViewStateMode

取得或設定這個控制項的檢視狀態模式。

(繼承來源 Control)
Visible

取得或設定值,指出伺服器控制項是否會轉譯為頁面上的 UI。

(繼承來源 Control)
Width

取得或設定 Web 伺服器控制項的寬度。

(繼承來源 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriterTag 中。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
AddedControl(Control, Int32)

在子控制項加入 Control 物件的 Controls 集合後呼叫。

(繼承來源 Control)
AddParsedSubObject(Object)

通知伺服器控制項,XML 或 HTML 項目已剖析,並將項目加入伺服器控制項的 ControlCollection 物件中。

(繼承來源 Control)
ApplyStyle(Style)

將指定樣式的任何非空白項目加入到 Web 控制項中,覆寫控制項的任何現有的樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
ApplyStyleSheetSkin(Page)

將頁面樣式表中所定義的樣式屬性套用至控制項。

(繼承來源 Control)
BeginRenderTracing(TextWriter, Object)

開始進行轉譯資料的設計階段追蹤。

(繼承來源 Control)
BuildProfileTree(String, Boolean)

收集伺服器控制項的相關資訊,並在頁面啟用追蹤時將此資訊傳遞至 Trace 屬性以顯示之。

(繼承來源 Control)
ChangeMode(DetailsViewMode)

DetailsView 控制項切換為指定的模式。

ClearCachedClientID()

將快取的 ClientID 值設定為 null

(繼承來源 Control)
ClearChildControlState()

刪除伺服器控制項之子控制項的控制項狀態資訊。

(繼承來源 Control)
ClearChildState()

刪除所有伺服器控制項之子控制項的檢視狀態和控制項狀態資訊。

(繼承來源 Control)
ClearChildViewState()

刪除所有伺服器控制項之子控制項的檢視狀態資訊。

(繼承來源 Control)
ClearEffectiveClientIDMode()

將目前的控制項執行個體和任何子控制項的 ClientIDMode 屬性設定為 Inherit

(繼承來源 Control)
ConfirmInitState()

設定資料繫結控制項之初始化的狀態。

(繼承來源 BaseDataBoundControl)
CopyBaseAttributes(WebControl)

將不被 Style 物件封裝的屬性從指定的 Web 伺服器控制項複製到呼叫這個方法的 Web 伺服器控制項上。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
CreateAutoGeneratedRow(AutoGeneratedFieldProperties)

使用指定的欄位屬性,建立表示自動產生資料列欄位的 AutoGeneratedField 物件。

CreateAutoGeneratedRows(Object)

針對指定的資料項目,建立一組自動產生的資料列欄位。

CreateChildControls()

根據儲存在檢視狀態中的值,建立用來呈現複合資料繫結控制項的控制項階層架構。

(繼承來源 CompositeDataBoundControl)
CreateChildControls(IEnumerable, Boolean)

建立用來呈現 DetailsView 控制項的控制階層架構。

CreateControlCollection()

建立新的 ControlCollection 物件來保存伺服器控制項的子控制項 (常值和伺服器)。

(繼承來源 Control)
CreateControlStyle()

建立 DetailsView 控制項的預設資料表樣式物件。

CreateDataSourceSelectArguments()

建立傳遞至 Select 命令的 DataSourceSelectArguments 物件。

CreateFieldSet(Object, Boolean)

建立自動產生與使用者定義資料列欄位的完整集合,以便用來產生控制階層架構。

CreateRow(Int32, DataControlRowType, DataControlRowState)

建立使用指定項目索引、資料列型別和資料列狀態的 DetailsViewRow 物件。

CreateTable()

建立 DetailsView 控制項的包含資料表。

DataBind()

呼叫基底類別的 DataBind() 方法。

DataBind(Boolean)

使用會引發 DataBinding 事件的選項,繫結資料來源至叫用的伺服器控制項及其所有子控制項。

(繼承來源 Control)
DataBindChildren()

繫結資料來源至伺服器控制項的子控制項。

(繼承來源 Control)
DeleteItem()

將目前的資料錄從資料來源中刪除。

Dispose()

啟用伺服器控制項,在它從記憶體釋放之前執行最後清除。

(繼承來源 Control)
EndRenderTracing(TextWriter, Object)

結束轉譯資料的設計階段追蹤。

(繼承來源 Control)
EnsureChildControls()

判斷伺服器控制項是否包含子控制項。 如果不包含,則建立子控制項。

(繼承來源 Control)
EnsureDataBound()

在確認資料清單控制項需要資料繫結,且已指定有效的資料來源控制項後,呼叫 DataBind() 方法。

EnsureID()

為尚未指定識別項的控制項,建立識別項。

(繼承來源 Control)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
ExtractRowValues(IOrderedDictionary, Boolean, Boolean)

擷取每個顯示欄位的值,並將它們儲存在指定的 IOrderedDictionary 物件中。

FindControl(String)

在目前命名容器搜尋具有指定 id 參數的伺服器控制項。

(繼承來源 Control)
FindControl(String, Int32)

使用指定的 id 和有助於搜尋之 pathOffset 參數中所指定的整數,在目前的命名容器中搜尋伺服器控制項。 您不應該覆寫這個版本的 FindControl 方法。

(繼承來源 Control)
Focus()

設定控制項的輸入焦點。

(繼承來源 Control)
GetCallbackResult()

傳回以控制項為目標之回呼事件的結果。

GetCallbackScript(IButtonControl, String)

使用指定的引數,傳回建立的回呼字串。

GetData()

擷取 DataSourceView 物件,資料繫結控制項會用來執行資料作業。

(繼承來源 DataBoundControl)
GetDataSource()

擷取與資料繫結控制項關聯的 IDataSource 介面 (如果有的話)。

(繼承來源 DataBoundControl)
GetDesignModeState()

取得控制項的設計階段資料。

(繼承來源 Control)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetRouteUrl(Object)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(RouteValueDictionary)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(String, Object)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetRouteUrl(String, RouteValueDictionary)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetUniqueIDRelativeTo(Control)

傳回指定之控制項 UniqueID 屬性的前置部分。

(繼承來源 Control)
HasControls()

判斷伺服器控制項是否包含任何子控制項。

(繼承來源 Control)
HasEvents()

傳回值,指出控制項或任何子控制項的事件是否已註冊。

(繼承來源 Control)
InitializePager(DetailsViewRow, PagedDataSource)

建立 DetailsView 控制項的頁面巡覽列。

InitializeRow(DetailsViewRow, DataControlField)

初始化指定的 DetailsViewRow 物件。

InsertItem(Boolean)

將目前的資料錄插入資料來源。

IsBindableType(Type)

判斷指定的資料型別是否可以繫結至 DetailsView 控制項中的欄位。

IsLiteralContent()

判斷伺服器控制項是否只儲存常值內容。

(繼承來源 Control)
LoadControlState(Object)

載入需要保存之 DetailsView 控制項中屬性的狀態,即使 EnableViewState 屬性設為 false

LoadViewState(Object)

載入先前儲存的 DetailsView 控制項檢視狀態。

MapPathSecure(String)

擷取虛擬絕對路徑或相對路徑所對應至的實體路徑。

(繼承來源 Control)
MarkAsDataBound()

將檢視狀態中的控制項狀態設為已成功繫結至資料。

(繼承來源 DataBoundControl)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MergeStyle(Style)

將指定樣式的任何非空白項目複製到 Web 控制項,但不覆寫控制項的任何現有樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
OnBubbleEvent(Object, EventArgs)

決定 Web 伺服器控制項的事件是否要向上傳遞至網頁的使用者介面 (UI) 伺服器控制階層架構。

OnCreatingModelDataSource(CreatingModelDataSourceEventArgs)

引發 CreatingModelDataSource 事件。

(繼承來源 DataBoundControl)
OnDataBinding(EventArgs)

引發 DataBinding 事件。

(繼承來源 Control)
OnDataBound(EventArgs)

引發 DataBound 事件。

(繼承來源 BaseDataBoundControl)
OnDataPropertyChanged()

其中一個基底資料來源識別屬性變更之後,將資料繫結控制項重新繫結至其資料。

(繼承來源 DataBoundControl)
OnDataSourceViewChanged(Object, EventArgs)

引發 DataSourceViewChanged 事件。

OnInit(EventArgs)

引發 Init 事件。

OnItemCommand(DetailsViewCommandEventArgs)

引發 ItemCommand 事件。

OnItemCreated(EventArgs)

引發 ItemCreated 事件。

OnItemDeleted(DetailsViewDeletedEventArgs)

引發 ItemDeleted 事件。

OnItemDeleting(DetailsViewDeleteEventArgs)

引發 ItemDeleting 事件。

OnItemInserted(DetailsViewInsertedEventArgs)

引發 ItemInserted 事件。

OnItemInserting(DetailsViewInsertEventArgs)

引發 ItemInserting 事件。

OnItemUpdated(DetailsViewUpdatedEventArgs)

引發 ItemUpdated 事件。

OnItemUpdating(DetailsViewUpdateEventArgs)

引發 ItemUpdating 事件。

OnLoad(EventArgs)

處理 Load 事件。

(繼承來源 DataBoundControl)
OnModeChanged(EventArgs)

引發 ModeChanged 事件。

OnModeChanging(DetailsViewModeEventArgs)

引發 ModeChanging 事件。

OnPageIndexChanged(EventArgs)

引發 PageIndexChanged 事件。

OnPageIndexChanging(DetailsViewPageEventArgs)

引發 PageIndexChanging 事件。

OnPagePreLoad(Object, EventArgs)

設定資料繫結控制項在載入控制項之前的初始化狀態。

OnPreRender(EventArgs)

引發 PreRender 事件。

OnUnload(EventArgs)

引發 Unload 事件。

(繼承來源 Control)
OpenFile(String)

取得用來讀取檔案的 Stream

(繼承來源 Control)
PerformDataBinding(IEnumerable)

將指定的資料來源繫結至 DetailsView 控制項。

PerformSelect()

從關聯的資料來源擷取資料。

(繼承來源 DataBoundControl)
PrepareControlHierarchy()

設定 DetailsView 控制項的控制階層架構。

RaiseBubbleEvent(Object, EventArgs)

指派事件的任何來源和它的資訊至控制項的父控制項。

(繼承來源 Control)
RaiseCallbackEvent(String)

建立 GetCallbackEventReference 方法中回呼處理常式的引數。

RaisePostBackEvent(String)

回傳至伺服器時引發 DetailsView 控制項的適當事件。

RemovedControl(Control)

Control 物件的 Controls 集合中移除子控制項之後呼叫。

(繼承來源 Control)
Render(HtmlTextWriter)

使用指定的 DetailsView 物件,在用戶端上顯示 HtmlTextWriter 控制項。

RenderBeginTag(HtmlTextWriter)

將控制項的 HTML 開頭標記呈現在指定的寫入器中。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
RenderChildren(HtmlTextWriter)

將伺服器控制項子系的內容輸出至提供的 HtmlTextWriter 物件,再由這個物件在用戶端上寫入要轉譯的內容。

(繼承來源 Control)
RenderContents(HtmlTextWriter)

將控制項的內容呈現在指定的寫入器。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
RenderControl(HtmlTextWriter)

將伺服器控制項內容輸出至提供的 HtmlTextWriter 物件,並在啟用追蹤時儲存控制項的追蹤資訊。

(繼承來源 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 物件,輸出伺服器控制項內容至提供的 ControlAdapter 物件。

(繼承來源 Control)
RenderEndTag(HtmlTextWriter)

將控制項的 HTML 結尾標記呈現至指定的寫入器。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
ResolveAdapter()

取得負責呈現指定之控制項的控制項配置器。

(繼承來源 Control)
ResolveClientUrl(String)

取得瀏覽器可使用的 URL。

(繼承來源 Control)
ResolveUrl(String)

將 URL 轉換為要求用戶端可使用的 URL。

(繼承來源 Control)
SaveControlState()

儲存需要保存之 DetailsView 控制項中屬性的狀態,即使 EnableViewState 屬性設為 false

SaveViewState()

儲存 DetailsView 控制項的目前檢視狀態。

SetDesignModeState(IDictionary)

設定控制項的設計階段資料。

(繼承來源 Control)
SetPageIndex(Int32)

設定目前顯示於 DetailsView 控制項中之頁面的索引。

SetRenderMethodDelegate(RenderMethod)

指定事件處理常式委派,以呈現伺服器控制項及其內容至其父控制項。

(繼承來源 Control)
SetTraceData(Object, Object)

使用追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
SetTraceData(Object, Object, Object)

使用追蹤的物體、追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
TrackViewState()

標記起點,從此點開始追蹤並儲存 DetailsView 控制項的檢視狀態變更。

UpdateItem(Boolean)

更新資料來源中目前的資料錄。

ValidateDataSource(Object)

驗證資料繫結控制項繫結至的物件是該資料繫結控制項所使用的物件。

(繼承來源 DataBoundControl)

事件

CallingDataMethods

正在呼叫資料方法時發生。

(繼承來源 DataBoundControl)
CreatingModelDataSource

正在建立 ModelDataSource 物件時發生。

(繼承來源 DataBoundControl)
DataBinding

發生於伺服器控制項繫結至資料來源時。

(繼承來源 Control)
DataBound

在伺服器控制項繫結至資料來源之後發生。

(繼承來源 BaseDataBoundControl)
Disposed

發生於伺服器控制項從記憶體釋放時,這是在要求 ASP.NET 網頁時,伺服器控制項生命週期的最後階段。

(繼承來源 Control)
Init

發生於初始化伺服器控制項時,是其生命週期中的第一個步驟。

(繼承來源 Control)
ItemCommand

按一下 DetailsView 控制項中的按鈕時會發生這個事件。

ItemCreated

DetailsView 控制項中建立記錄時會發生這個事件。

ItemDeleted

發生於按一下 DetailsView 控制項內的 [刪除] 按鈕時,但是在刪除作業之後。

ItemDeleting

發生於按一下 DetailsView 控制項內的 [刪除] 按鈕時,但是在刪除作業之前。

ItemInserted

發生於按一下 DetailsView 控制項內的 [插入] 按鈕時,但是在插入作業之後。

ItemInserting

發生於按一下 DetailsView 控制項內的 [插入] 按鈕,但是在插入作業之前。

ItemUpdated

發生於按一下 DetailsView 控制項內的 [更新] 按鈕時,但在更新作業之後。

ItemUpdating

發生於按一下 DetailsView 控制項內的 [更新] 按鈕時,但在更新作業之前。

Load

發生於載入伺服器控制項至 Page 物件時。

(繼承來源 Control)
ModeChanged

發生於 DetailsView 控制項嘗試在編輯、插入和唯讀模式之間變更,但是在 CurrentMode 屬性更新之後。

ModeChanging

發生於 DetailsView 控制項嘗試在編輯、插入和唯讀模式之間變更,但是在 CurrentMode 屬性更新之前。

PageIndexChanged

發生於 PageIndex 屬性值在分頁作業之後變更時。

PageIndexChanging

發生於 PageIndex 屬性值在分頁作業前變更時。

PreRender

Control 物件載入之後但在呈現之前發生。

(繼承來源 Control)
Unload

發生於伺服器控制項從記憶體卸載時。

(繼承來源 Control)

明確介面實作

IAttributeAccessor.GetAttribute(String)

使用指定的名稱,取得 Web 控制項的屬性。

(繼承來源 WebControl)
IAttributeAccessor.SetAttribute(String, String)

將 Web 控制項的屬性設定為指定的名稱和值。

(繼承來源 WebControl)
ICallbackContainer.GetCallbackScript(IButtonControl, String)

建立 DetailsView 控制項的回呼指令碼。

ICallbackEventHandler.GetCallbackResult()

請參閱 GetCallbackResult() 方法。

ICallbackEventHandler.RaiseCallbackEvent(String)

使用指定的引數引發回呼事件。

IControlBuilderAccessor.ControlBuilder

如需這個成員的說明,請參閱 ControlBuilder

(繼承來源 Control)
IControlDesignerAccessor.GetDesignModeState()

如需這個成員的說明,請參閱 GetDesignModeState()

(繼承來源 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

如需這個成員的說明,請參閱 SetDesignModeState(IDictionary)

(繼承來源 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

如需這個成員的說明,請參閱 SetOwnerControl(Control)

(繼承來源 Control)
IControlDesignerAccessor.UserData

如需這個成員的說明,請參閱 UserData

(繼承來源 Control)
IDataBindingsAccessor.DataBindings

如需這個成員的說明,請參閱 DataBindings

(繼承來源 Control)
IDataBindingsAccessor.HasDataBindings

如需這個成員的說明,請參閱 HasDataBindings

(繼承來源 Control)
IDataBoundControl.DataKeyNames

如需這個屬性的說明,請參閱 DataKeyNames

IDataBoundControl.DataMember

如需這個屬性的說明,請參閱 DataMember

IDataBoundControl.DataSource

如需這個屬性的說明,請參閱 DataSource

IDataBoundControl.DataSourceID

如需這個屬性的說明,請參閱 DataSourceID

IDataBoundControl.DataSourceObject

如需這個屬性的說明,請參閱 DataSourceObject

IDataBoundItemControl.DataKey

如需這個屬性的說明,請參閱 DataKey

IDataBoundItemControl.Mode

如需這個屬性的說明,請參閱 Mode

IDataItemContainer.DataItemIndex

如需這個成員的說明,請參閱 DataItemIndex

IDataItemContainer.DisplayIndex

如需這個成員的說明,請參閱 DisplayIndex

IExpressionsAccessor.Expressions

如需這個成員的說明,請參閱 Expressions

(繼承來源 Control)
IExpressionsAccessor.HasExpressions

如需這個成員的說明,請參閱 HasExpressions

(繼承來源 Control)
IFieldControl.FieldsGenerator

如需這個屬性的說明,請參閱 FieldsGenerator

IParserAccessor.AddParsedSubObject(Object)

如需這個成員的說明,請參閱 AddParsedSubObject(Object)

(繼承來源 Control)
IPostBackContainer.GetPostBackOptions(IButtonControl)

如需這個成員的說明,請參閱 GetPostBackOptions(IButtonControl)

IPostBackEventHandler.RaisePostBackEvent(String)

如需這個成員的說明,請參閱 RaisePostBackEvent(String)

擴充方法

EnablePersistedSelection(BaseDataBoundControl)
已淘汰.

啟用要保存於資料控制項中且支援選取和分頁的選項。

FindDataSourceControl(Control)

傳回與指定之控制項的資料控制項相關聯的資料來源。

FindFieldTemplate(Control, String)

傳回在指定之控制項的命名容器中所指定資料行的欄位樣板。

FindMetaTable(Control)

傳回包含資料控制項的中繼資料表物件。

GetDefaultValues(INamingContainer)

取得所指定資料控制項的預設值集合。

GetMetaTable(INamingContainer)

取得所指定資料控制項中的資料表中繼資料。

SetMetaTable(INamingContainer, MetaTable)

設定所指定資料控制項中的資料表中繼資料。

SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>)

設定所指定資料控制項的資料表中繼資料及預設值對應。

SetMetaTable(INamingContainer, MetaTable, Object)

設定所指定資料控制項的資料表中繼資料及預設值對應。

TryGetMetaTable(INamingContainer, MetaTable)

判斷資料表中繼資料是否可供使用。

EnableDynamicData(INamingContainer, Type)

針對指定的資料控制項啟用動態資料行為。

EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>)

針對指定的資料控制項啟用動態資料行為。

EnableDynamicData(INamingContainer, Type, Object)

針對指定的資料控制項啟用動態資料行為。

適用於

另請參閱