Chapter 3. Data Binding


3. Data Binding

IN THIS CHAPTER, we look at the declarative data sources and the new data-bound controls introduced with ASP.NET 2.0. Of all the features introduced in this release, declarative data binding undoubtedly has the most impact on developers. Instead of programmatically populating controls with queries issued through ADO.NET, data source controls provide a way of populating controls with data declaratively. The end result is that developers end up writing much less code to accomplish the same tasks. This model is flexible enough to support many different types of data access as well, ranging from standard parameterized SQL statements to stored procedure calls to full-blown object-oriented data access layers.

Most of the samples shown in this chapter are based on a database called "moviereviews" that contains two tables: movies and reviews. Each table has a single primary key marked as an identity column, and there is a foreign key reference from the reviews table to the movies table. Listing 3-1 shows the creation script for these two tables.[1]

[1] This script, as well as an accompanying sample data creation script, is available for download as part of the sample collection for this book at http://pluralsight.com/essentialasp.net2/.

Listing 3-1. Creation script for moviereviews sample database

CREATE TABLE movies (   movie_id            INT IDENTITY(1,1) NOT NULL                        CONSTRAINT pk_movies PRIMARY KEY CLUSTERED,   title               NVARCHAR(64) NOT NULL,   release_date        DATETIME NOT NULL ) GO CREATE TABLE reviews (   review_id    INT IDENTITY(1,1) NOT NULL                 CONSTRAINT pk_reviews PRIMARY KEY CLUSTERED,   movie_id     INT NOT NULL CONSTRAINT fk_reviews_movies                 FOREIGN KEY (movie_id) REFERENCES movies (movie_id),   summary      VARCHAR(64) NOT NULL,   rating       INT NOT NULL,   review       NVARCHAR(512) NOT NULL,   reviewer     NVARCHAR(64) NULL ) GO 




Essential ASP. NET 2.0
Essential ASP.NET 2.0
ISBN: 0321237706
EAN: 2147483647
Year: 2006
Pages: 104

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net