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

Using the ObjectDataSource Control

Most of the applications we’ll look at in this book are two-tier, separating the user interface from the backend data. Many larger commercial applications, however, are n-tier, with at least one middle business-logic layer to separate the retrieval of data from a database from the manipulation (and validation) of that data before presentation. This separation means that business-layer logic can be more readily tested and refactored so code is not duplicated between pages when it does not need to be.

Take, for example, the Customer class in Example 7-1. It’s necessarily simple for the purposes of this example and generates its own data rather than querying any external source of data, but the key idea is that it contains several methods—such as GetCustomers—returning different views of the customer data in the database as a generic DataSet container for the ObjectDataSource to then access and present onscreen.

Example 7-1. A simple business layer object class

using System.Data; /// <summary> /// An example Customer class /// </summary> public class Customer { public int CustomerID { get; set; } public string Name { get; set; } public string City { get; set; } public Customer( ) { } /// <summary> /// Gets Customers and returns them in DataSet /// </summary> public DataSet GetCustomers( ) { // Add logic here for actual retrieval of data from DB DataSet ds = new DataSet( ); DataTable dt = new DataTable("Customers"); dt.Columns.Add("CustomerId", typeof(System.Int32)); ...
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