Data Controls




One of the important goals of ASP.NET 2.0 is 70 percent code reduction. The data controls supplied with
ASP.NET 2.0 play an important role in making this ambitious goal a reality. Data source controls provide a
consistent and extensible method for declaratively accessing data from Web pages. Data source controls
supplied with ASP.NET 2.0 are as follows:

  <asp:SqlDataSource> —This data source control is designed to work with SQL Server, OLE

DB, ODBC, and Oracle databases. Using this control, you can also enable select, update, delete,
and insert data using SQL commands.

  <asp:ObjectDataSource> — N-Tier methodology allows you to create Web applications that

are not only scalable and but also easier to maintain. N-Tier principle also enables clean separa-
tion thereby allowing you to easily add new functionalities. In an N-Tier application, the middle
tier objects may return complex objects that you have to process in your ASP.NET presentation
layer. Keeping this requirement in mind, Microsoft has created this new control that allows you
to seamlessly integrate the data returned from the middle layer objects with the ASP.NET
presentation layer.

  <asp:AccessDataSource>— This is similar to the SqlDataSource control, except that it is

designed to work with Access databases.

  <asp:XmlDataSource> —The XmlDataSource control allows you to bind to XML data, which

can come from a variety of sources such as an external XML file, a DataSet object and so on.
After the XML data is bound to the XmlDataSource control, this control can then act as a source
of data for data-bound controls such as TreeView and Menu.

  <asp:SiteMapDataSource>— The SiteMapDataSource control provides a site navigation

framework that makes the creation of a site navigation system a breezy experience. Accomplishing
this requires the use of a new XML file named web.sitemap that lays out the pages of the site in
a hierarchical XML structure. After you have the site hierarchy in the web.sitemap file, you can
then data-bind the SiteMapDataSource control with the web.sitemap file. The contents of the

SiteMapDataSource control can then be bound to data-aware controls such as TreeView, Menu
control, and so on.

Now that you have had a look at the data source controls supplied with ASP.NET 2.0, this section examines
the data-bound controls that you will normally use to display data contained in the data source controls.
These data-bound controls bind data automatically.

One of the nice things about data-bound control is that the development environment automatically
guides developers through the process of binding a data control to a data source. Developers are
prompted to select the particular data source to use for selecting, inserting, updating, and deleting data.
The feature that walks the developers through this process is called Smart Tasks. This is explained in
detail in the Visual Studio Improvements section in the later part of this chapter.