DetailsView 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從資料表的資料來源顯示單一資料錄的值,其中每個資料列都代表資料錄的欄位。 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
,這會針對資料來源中可系結類型的每個欄位自動產生系結資料欄欄位物件。 有效的可系結型別為 String 、 DateTime 、 Decimal 、 Guid 和一組基本類型。 然後,每個欄位都會以文字的形式顯示在資料列中,以每個欄位出現在資料來源中的順序。
自動產生資料列提供快速且簡單的方式,以在記錄中顯示每個欄位。 不過,若要使用 DetailsView 控制項的進階功能,您必須明確宣告要包含在 控制項中的資料 DetailsView 欄欄位。 若要宣告資料欄欄位,請先將 AutoGenerateRows 屬性設定為 false
。 接下來,在控制項的 DetailsView 開頭和結束記號之間新增開頭和結尾 <Fields>
標記。 最後,列出您想要在開頭和結尾 <Fields>
標記之間包含的資料欄欄位。 指定的資料欄欄位會依列出的順序新增至 Fields 集合。 集合 Fields 可讓您以程式設計方式管理 控制項中的資料 DetailsView 欄欄位。
注意
自動產生的資料欄欄位不會新增至 Fields 集合。
注意
明確宣告的資料欄欄位可以與自動產生的資料欄欄位一起顯示。 同時使用這兩個欄位時,會先轉譯明確宣告的資料欄欄位,後面接著自動產生的資料欄欄位。
系結至資料
控制項 DetailsView 可以系結至資料來源控制項 (,例如 SqlDataSource 控制項或 ObjectDataSource 控制項) ,或實作 System.Collections.IEnumerable 介面的任何資料來源集合,例如 System.Data.DataView 、 System.Collections.ArrayList 、 System.Collections.Generic.List<T> 或其他集合類型。 使用下列其中一種方法,將 DetailsView 控制項系結至適當的資料來源類型:
若要系結至資料來源控制項,請將 DataSourceID 控制項的 DetailsView 屬性設定為 ID 資料來源控制項的值。 控制項 DetailsView 會自動系結至指定的資料來源控制項。 這是系結至資料的慣用方法。
若要系結至實作 System.Collections.IEnumerable 介面的資料來源,請以程式設計方式將 控制項的 DetailsView 屬性設定 DataSource 為數據源,然後呼叫 DataBind 方法。
如需資料系結的詳細資訊,請參閱 系結至資料庫。
安全性
此控制項可用來顯示使用者輸入,其中可能包含惡意用戶端腳本。 在應用程式中顯示可執行檔腳本、SQL 語句或其他程式碼之前,請先檢查從用戶端傳送的任何資訊。 ASP.NET 提供輸入要求驗證功能,以封鎖使用者輸入中的腳本和 HTML。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。 也會提供驗證服務器控制項來評估使用者輸入。 如需詳細資訊,請參閱 驗證服務器控制項語法。
資料作業
控制項 DetailsView 提供內建功能,可讓使用者透過控制項中的專案來更新、刪除、插入和分頁。 DetailsView當控制項系結至資料來源控制項時, DetailsView 控制項可以利用資料來源控制項的功能,並提供自動更新、刪除、插入和分頁功能。
注意
控制項 DetailsView 可為其他類型的資料來源提供更新、刪除、插入和分頁作業的支援;不過,您必須在適當的事件處理常式中提供這些作業的實作。 如需詳細資訊,請參閱ItemDeleting、ItemInserting和ItemUpdating。
控制項 DetailsView 可以分別將 、 AutoGenerateDeleteButton 或 屬性設定 AutoGenerateEditButton 為 true
,以自動新增 CommandField 具有 [編輯]、[刪除] 或 AutoGenerateInsertButton [新增] 按鈕的資料欄欄位。 不同于 [刪除] 按鈕 (會立即刪除選取的記錄) 按一下 [編輯] 或 [新增] 按鈕時, DetailsView 控制項會分別進入編輯或插入模式。 在編輯模式中,[編輯] 按鈕會取代為 [更新] 和 [取消] 按鈕。 適用于欄位資料類型的輸入控制項 (,例如 TextBox 或 CheckBox 控制項) ,會顯示欄位的值以供使用者修改。 按一下 [更新] 按鈕會更新資料來源中的記錄,然後按一下 [取消] 按鈕會放棄任何變更。 同樣地,在插入模式中,[新增] 按鈕會取代為 [插入] 和 [取消] 按鈕,並顯示空白輸入控制項,讓使用者輸入新記錄的值。
注意
您也可以在 、 CommandField 或 TemplateField 資料欄欄位中手動定義更新、刪除和插入命令按鈕 ButtonField 。 控制項 DetailsView 會辨識屬性設定為 「Edit」、「Update」、「Delete」、「New」、「Insert」 或 「Cancel」 的按鈕 CommandName ;不過,您仍然必須自行提供功能。 如需詳細資訊,請參閱ItemDeleting、ItemInserting和ItemUpdating。
控制項 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 、、 DataBound 、 Disposed 、 Init 、 Load 、 PreRender 和 Render 。
事件 | 描述 |
---|---|
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.NET 和 ASP.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 |
取得或設定包含了此控制項之 Page 或 UserControl 物件的相對應用程式虛擬目錄。 (繼承來源 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 |
取得值,這個值表示當控制項的 |
TabIndex |
取得或設定 Web 伺服器控制項的定位索引。 (繼承來源 WebControl) |
TagKey |
取得 DetailsView 控制項的 HtmlTextWriterTag 值。 |
TagName |
取得控制項標記的名稱。 這個屬性主要由控制項開發人員使用。 (繼承來源 WebControl) |
TemplateControl |
取得或設定包含了此控制項之樣板的參考。 (繼承來源 Control) |
TemplateSourceDirectory |
取得包含目前伺服器控制項的 Page 或 UserControl 的虛擬目錄。 (繼承來源 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) |
方法
事件
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) |
明確介面實作
擴充方法
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) |
針對指定的資料控制項啟用動態資料行為。 |