Skip to Main Content
Programming ASP.NET 3.5, 4th Edition
book

Programming ASP.NET 3.5, 4th Edition

by Dan Maharry, Dan Hurwitz, Jesse Liberty
October 2008
Intermediate to advanced content levelIntermediate to advanced
1166 pages
28h 31m
English
O'Reilly Media, Inc.
Content preview from Programming ASP.NET 3.5, 4th Edition

One Record at a Time: DetailsView

With lists in hand, let’s expand your frame of data view from a couple of fields per row to an entire row. ASP.NET v2 introduced two new controls, the DetailsView and the FormView, to work with one row of information at a time. The DetailsView, which you’ll look at now, applies a structure to the presentation of this information—it places it in the rows and columns of an HTML table—whereas the FormView, which you’ll look at later, removes that structure and asks you to define your own.

To demonstrate the basic workings of the DetailsView, add to the C8_DataAccess website a new page called DetailsView.aspx and add a SqlDataSource to it that retrieves all the information from the Customer table. Then, add a DetailsView control to the page and use its Common Tasks panel to connect it to the data source. Example 8-3 shows the resultant markup.

Example 8-3. DetailsView.aspx initial markup

<%@ Page Language="C#" AutoEventWireup="true"
   CodeFile="DetailsView.aspx.cs" Inherits="DetailsView" %>

<!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>DetailsView Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
      <asp:SqlDataSource ID="dsCustomers" runat="server"
         ConnectionString=
            "<%$ ConnectionStrings:AWLTConnection%>"
         SelectCommand="SELECT * FROM [SalesLT].[Customer]" />
 <asp:DetailsView ID="DetailsView1" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Microsoft® ASP.NET 3.5

Programming Microsoft® ASP.NET 3.5

Dino Esposito
Learning ASP.NET 3.5, 2nd Edition

Learning ASP.NET 3.5, 2nd Edition

Brian MacDonald, Dan Hurwitz, Jesse Liberty
Pro ASP.Net 4 in C# 2010

Pro ASP.Net 4 in C# 2010

Matthew MacDonald, Adam Freeman, Mario Szpuszta
Programming .NET 3.5

Programming .NET 3.5

Jesse Liberty, Alex Horovitz

Publisher Resources

ISBN: 9780596156657Supplemental ContentErrata Page