Export (0) Print
Expand All

DetailsView Constructor

Initializes a new instance of the DetailsView class.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public DetailsView()

Use this constructor to initialize a new instance of the DetailsView class. 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.

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"
<html xmlns="http://www.w3.org/1999/xhtml" >

    <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 = 

        // Add the DetailsView object to the Controls collection
        // of the PlaceHolder control.




    <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"

        <!-- 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]"
            "server=localhost;database=pubs;integrated security=SSPI"


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft