asp.net.ph

Skip Navigation Links

DetailsView Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Displays the values of a single record from a data source in a table, where each data row represents a field of the record. The DetailsView control allows you to edit, delete, and insert records.

Declarative Syntax

For information on the individual members of this class, see DetailsView in the class library.

Remarks

The DetailsView control renders the contents of a single record from a data source into a table, where each field of the record is displayed in a row of the table. It can be used in combination with a GridView control for master-detail scenarios.

Syntax Example

The following example demonstrates how to use a DetailsView control in combination with a GridView control for a simple master-detail scenario. It displays the details of an item that is selected in the GridView control.

For more information on using the DetailsView control, see DetailsView Web Server Control.

<table cellpadding=5>
<tr>
   <td>
   <asp:gridview id="customersGrid" runat="server"
      cellpadding=3
      datasourceid="customers"
      datakeynames = "CustomerID"
      autogeneratecolumns=false>
      <columns>
         <asp:commandfield showselectbutton />

         <asp:boundfield datafield = "ContactName" headertext = "ContactName" />

         <asp:boundfield datafield = "CompanyName" headertext = "CompanyName" />
      </columns>
   </asp:gridview>
   </td>

   <td valign = "top">
   <asp:detailsview id="customerDetails" runat="server"
      width=300 cellpadding=3
      datasourceid="details"
      datakeynames = "CustomerID">
   </asp:detailsview>
   </td>
</tr>
</table>

<asp:sqldatasource id="details" runat="server"
   connectionstring = "<%$ ConnectionStrings:aspnet %>"
   SelectCommand = "SELECT * FROM Customers WHERE CustomerID = @CustomerID">

   <selectparameters>
      <asp:controlparameter controlid="customersGrid" name = "CustomerID"
         propertyname = "SelectedValue"
         type = "String" />
   </selectparameters>
</asp:sqldatasource>

<asp:sqldatasource id="customers" runat="server"
   connectionstring = "<%$ ConnectionStrings:aspnet %>"
   SelectCommand = "SELECT CompanyName, ContactName, CustomerID FROM Customers" />

 Show me 

See Also

DetailsView Class   DetailsView Web Server Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note