Binding to Business Objects
Most of the applications that we’ve looked at in this book have been two-tier, separating the User Interface from the back-end data. Many larger commercial applications, however, are n-tier, with at least a middle business-logic layer to separate retrieval of data from the database from manipulation (and validation) of that data before presentation.
An example of a middle-tier business object would be to create a stateless class to encapsulate business logic, and a “model” class that knows how to load and store data from the database.
Tip
This follows the Model View Controller (MVC) design pattern popular with many object-oriented programmers (see, for example, the article “Model-View-Controller” on MSDN.com: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/desmvc.asp).
To illustrate implementing the n-tier MVC pattern, we’ll create a stateless business class CustomerBusinessLogic and a “model” of the Customer class named NorthWind customer. We’ll bind an ObjectDataSource
to the stateless business-logic class which will use the Model class to get and retrieve data about customers in the NorthWind database.
To begin, create a new web application called NTierDataSource. Add a GridView
and use the smart tag and the properties to set the columns from the Customer table you’d like to display, as shown in Example 10-16.
Example 10-16. GridView declaration in default.aspx from NTierDataSource
<asp:GridView ID="GridView1" runat="server" ...
Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.