by August 3, 2004 0 comments

ASP.NET 1.1 along with VS.NET made the life of Web developers much easier thanks to the rich data environment it had. The System.Data namespace along with the associated managed providers for SQL Server, Oracle, OLEDB and ODBC made programming and using databases a dream. Almost all controls that could be placed on the page, such as Textbox and DropDownList, were data aware. Inclusion of rich data controls, such as the DataGrid and DataList, were a boon for developers. 

Developers can now be even happier, since a new and enhanced data model comes in ASP.NET 2.0. In this model, apart from the standard namespaces, you have two types of controls: Data Source Controls and Data Bound Controls.

Data Source Controls are non-UI controls, that is, they do not have a visible user interface and are not rendered on the client. Instead, they simply point to (reference) different backend data sources, which could be a database, XML file, a Web service or a business layer object. These controls provide all the data capabilities, such as sorting, filtering, paging and insert/update/ deleting.

Applies to: .NET developers
USP: Faster database handling from Web pages

Data Bound Controls, on the other hand, are the frontend controls. These controls get rendered on the client browser. The Data Bound Controls bind to a Data Source Control to retrieve data to display. In many cases, this can even happen automatically, where a Data Bound Control of a specific type can detect whether a Data Source Control of the type it expects, is already present and can bind to it without developer intervention (of course, one downside of such intelligent control is that it makes developers lazy.)

So what do these controls look like? A Data Source Control could look something like this, if your backend is SQL Server.

In case your backend is an XML file, then it would look something like this.

You can easily set common functionality for the GridView from its SmartTag in VS.NET 2005

By default there are six data sources: SqlDataSource (uses not only SQL Server, but any database using the managed providers), ObjectDataSource (uses any business object), AccessDataSource, DataSetDataSource, SiteMapDataSource (uses an XML file to represent the website’s structure) and XMLDataSource (for any other XML file). 

These Data Source Controls are intelligent enough to bind to the controls at the appropriate time in the page
lifecycle. You can, of course, very easily extend and handle the controls events. Not just that, you can also quite easily create your own Data Source Controls if the default ones don’t ‘wing’ it. 

The Data Bound Controls are the more familiar ones. The good, old DataGrid continues to exist. However, a much more flexible and powerful new control, GridView control, offers everything that the DataGrid does and more. Other new controls that come with VS.NET 2005 are: the
DetailsView, TreeView and the Menu. Each of these, as well as old favorites, such as the DropDownList and DataList are completely data source aware and can use any of the Data Source Controls implicitly.

The resultant GridView on a page has all the functionality, but without writing any code, unlike the DataGrid

This allows a page developer to use the capabilities of the Data Source Controls from the new data bound controls quite easily. For instance, you no longer have to write even the three to four lines of code that you needed to, for enabling sorting or paging for a
DataGrid. Using a SqlDataSource and GridView you can enable a few options and both the controls work in tandem to provide you the functionality.

The new controls do not just get relational data (as in from an RDBMS). They can also work with hierarchical data. The SiteMapDataSource and the XMLDataSource are ones that can use this sort of data. The TreeView and Menu controls are the ones that can use these sort of hierarchical data and display them natively. 

Next month, we’ll start looking at samples of how you can start using these new capabilities of ASP.NET in your Web applications. We will use the beta of VS.NET 2005 or the new express Visual Web Developer beta-a lite version of VS.NET that is suitable for hobbyists, students and small-scale developers to do this. 

Vinod Unny
Enterprise InfoTech

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.