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

Many Records at a Time: GridView

Whereas the DetailsView control works with one record from a query at a time on-screen, the GridView control displays many, as shown in Figure 8-14. It is the go-to control for displaying tabular data on-screen and, as it is also derived from the CompositeDataBoundControl class, it shares many of its properties, events, and methods with the DetailsView control.

To demonstrate, create a new web page called GridView.aspx in the C8_DataAccess website and drag a SqlDataSource and a GridView control onto it. Set the DataSource to select all the data from the Customer table and then set the GridView to use the data source using its DataSourceID property, as shown in Example 8-6.

Example 8-6. Bare-bones markup for GridView.aspx

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

<!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>GridView Demo</title>
</head>

<body>
   <form id="form1" runat="server">
   <div>
      <asp:SqlDataSource ID="dsCustomers" runat="server"
         ConnectionString="<%$ ConnectionStrings:AWLTConnection %>"
         SelectCommand="SELECT * FROM [SalesLT].[Customer]" />
      <asp:GridView ID="gvwCustomers"
         runat="server" DataSourceID="dsCustomers" />
   </div>
   </form>
</body>
</html>

If you compare this to the bare-bones markup for the DetailsView in Example 8-3, you’ll see the code is ...

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