DetailsView 构造函数
定义
初始化 DetailsView 类的新实例。Initializes a new instance of the DetailsView class.
public:
DetailsView();
public DetailsView ();
Public Sub New ()
示例
下面的代码示例演示如何使用构造函数将控件动态添加 DetailsView 到页中。The following code example demonstrates how to use the constructor to dynamically add a DetailsView control to a page.
<!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>
<title>DetailsView Constructor Example</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Create a new DetailsView object.
DetailsView storeDetailsView = new DetailsView();
// Set the DetailsView object's properties.
storeDetailsView.ID = "StoresDetailsView";
storeDetailsView.DataSourceID = "StoresSqlDataSource";
storeDetailsView.AutoGenerateRows = true;
storeDetailsView.AllowPaging = true;
storeDetailsView.PagerSettings.Mode =
PagerButtons.NextPrevious;
// Add the DetailsView object to the Controls collection
// of the PlaceHolder control.
DetailsViewPlaceHolder.Controls.Add(storeDetailsView);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsView Constructor Example</h3>
<!-- Use a PlaceHolder control as the container for the -->
<!-- dynamically generated DetailsView control. -->
<asp:PlaceHolder id="DetailsViewPlaceHolder"
runat="server"/>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database. -->
<asp:sqldatasource id="StoresSqlDataSource"
selectcommand="SELECT [stor_id], [stor_name], [stor_address],
[city], [state], [zip] FROM [stores]"
connectionstring=
"server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
<!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>
<title>DetailsView Constructor Example</title>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new DetailsView object.
Dim storeDetailsView As New DetailsView()
' Set the DetailsView object's properties.
storeDetailsView.ID = "StoresDetailsView"
storeDetailsView.DataSourceID = "StoresSqlDataSource"
storeDetailsView.AutoGenerateRows = True
storeDetailsView.AllowPaging = True
storeDetailsView.PagerSettings.Mode = _
PagerButtons.NextPrevious
' Add the DetailsView object to the Controls collection
' of the PlaceHolder control.
DetailsViewPlaceHolder.Controls.Add(storeDetailsView)
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsView Constructor Example</h3>
<!-- Use a PlaceHolder control as the container for the -->
<!-- dynamically generated DetailsView control. -->
<asp:PlaceHolder id="DetailsViewPlaceHolder"
runat="server"/>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database. -->
<asp:sqldatasource id="StoresSqlDataSource"
selectcommand="SELECT [stor_id], [stor_name], [stor_address],
[city], [state], [zip] FROM [stores]"
connectionstring=
"server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
注解
使用此构造函数初始化类的新实例 DetailsView 。Use this constructor to initialize a new instance of the DetailsView class. 若要将控件动态添加 DetailsView 到页面,请创建新的 DetailsView 对象,设置其属性,然后将其添加到 Control.Controls 容器控件的集合,如 PlaceHolder 。To dynamically add a DetailsView control to a page, create a new DetailsView object, set its properties, and then add it to the Control.Controls collection of a container control, such as PlaceHolder.