CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, October 03, 2006

Data Source Control Basics - Accessing and Updating Data in ASP.NET 2.0

Introduction
When I started my career as a web developer, Microsoft's Active Server Pages version 2.0 had just burst onto the scenes (classic ASP, mind you, not .NET). Back in my day, web developers were responsible for writing code to both access and display data. That is, we had to write code that queried the database and then had to write more code to squirt out the appropriate data surrounded by the applicable HTML elements. ASP.NET version 1.x simplified this process with the host of data Web controls (the DataGrid, DataList, Repeater, DropDownList, and so on). With just two lines of code these controls could emit their own, proper HTML elements when given an arbitrary data source. Today, with ASP.NET version 2.0 and its data source controls, developers can both access data and display it without writing a lick of code. You kids have it so easy these days!

The Benefits of the Data Source Controls
One of ASP.NET version 1.x's biggest improvements over its precursor, classic ASP, was the data Web controls had the ability to render HTML markup from an arbitrary data source without having to write a lick of code. This enhancement introduced two advantages: it saved having to write a lot of code and markup, and required less domain expertise from developers. When emitting data to a web page with classic ASP, page developers needed to write code to iterate through the database results and display not only the contents of the current record, but also the HTML that accompanied the record.

For example, to display the results of a database query in an HTML <table>, a classic ASP developer would have to first retrieve the data, then emit the starting <table> tag, followed by a loop that enumerated the records in the RecordSet. For each database record, a table row (<tr>) would be emitted, and for each field in that database record a table column (<td>). Finally, after exhausting the data, a closing table tag would complete the code. If you've never had to write classic ASP code consider yourself lucky - it was inherently messy, especially when applying more involved formatting, such as having alternating row colors or formatting cells based on various conditions. The data Web control model in ASP.NET 1.x removed the expanse of code needed to be written.

Data Source Control Basics - Accessing and Updating Data in ASP.NET 2.0

Post a Comment