![]() |
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Published: Wednesday, December 29, 2004 By Scott Mitchell
Introduction That being said, for those of us who have worked with ASP.NET now for the past several years, another change is in the winds, moving from ASP.NET 1.x to ASP.NET 2.0. Fortunately, the downside of change is less than what it could be. Those who moved from classic ASP to ASP.NET no doubt would agree that such a transition involved a fairly steep learning curve. The move to ASP.NET 2.0 from ASP.NET 1.x is going to be easier because the underlying fundamentals between the two are the same. However, there are a slew of new things coming forward with ASP.NET 2.0. A whole lotta new things. In this article I'll briefly discuss some of the bigger new things in ASP.NET 2.0, and focus in on one of the more relevant new things: the new and improved means for working with data in an ASP.NET 2.0 Web page. (This article was written during the Beta 1 time frame of ASP.NET 2.0; the technologies discussed may or may not make it to the final version of ASP.NET 2.0. You can download the latest 2.0 beta bits from http://labs.msdn.microsoft.com/.)
A Taste of the New Things to Come Another major improvement in the area of working with data is the ASP.NET GridView Web control. The GridView is the next version of the DataGrid, one that has common functionality wrapped up, thereby requiring less code and effort from developers wishing to utilize this common functionality. For example, creating a sortable, pageable, editable GridView in ASP.NET 2.0 requires no code, whereas ASP.NET 1.x developers wanting to do the same with a DataGrid must write a decent amount of code. Another task Web developers oftentimes find themselves faced with is creating a site that has user accounts. This involves a number of steps, such as writing pages to create user accounts, to login, to send a password reminder, and so on. Additionally, once a user has logged on, many sites want to be able to easily reference user-specific data. For example, when logged into your bank's Web site, on the left hand column you might see your account balance, while on the right hand side might be a series of recent transactions you've performed. ASP.NET 2.0 contains a built-in membership API that makes it a cinch to create new user accounts, reset passwords, log on users, load specific user settings, and so on. (You can, in fact, check out the Member Management Component Prototype for ASP.NET 1.x. This free library from Microsoft illustrates a number of the new membership and personalization features that will be present in ASP.NET 2.0.) There are also a bevy of new Web controls that address commonly created user interface pieces in ASP.NET 1.x Web sites. There's a Login Web control, for example, that saves you the need for creating the UI elements for collecting a user's Username and Password. There's a SiteMap control that shows a user where they are in the Web site's content; a TreeView control; a Menu control; and so on.
This is just a taste of the new features of ASP.NET 2.0. There are dozens of other new features that will, no doubt, warrant
their own articles as ASP.NET 2.0's release draws nearer. And if all of these new changes in just ASP.NET weren't enough,
Visual Studio .NET has had a major facelift for 2.0. The new version of Visual Studio .NET, called Visual Studio 2005, provides
a much improved developer experience. There's IntelliSense in the HTML portions of ASP.NET pages and in
Working with Data in ASP.NET 2.0 Well, writing code to work with database data is a thing of the past with ASP.NET 2.0 thanks to a new suite of Web controls called the DataSource controls. These controls, as their names imply, are designed to provide control-like functionality for accessing data. That is, to grab data from, say, a SQL Server database, you need only to drag the appropriate DataSource Web control (the SqlDataSource control, in this example) onto the Designer. Upon doing so you can configure the DataSource control through a wizard. You'll be prompted to select the database connection to use and the query or stored procedure to run. The screenshots below show the various screens in the SqlDataSource wizard.
In addition to specifying a SELECT statement you can also use the DataSource to specify INSERT, UPDATE, and DELETE statements
to boot. Realize that a DataSource control just provides access to data. In order to actually work with the data, such
as displaying said data in the Web page, you need to use an appropriate Web control. For example, the GridView control (ASP.NET
2.0's improved version of the DataGrid) can be used to display, edit, and delete data.
To display data, all that you need to do is drag the GridView onto the page and set its
Accessing Different Types of Data
The SqlDataSource and AccessDataSource controls are pretty straightforward. Both provide a wizard similar to the one shown in
the screenshots above. (The AccessDataSource wizard differs slightly from the SqlDataSource wizard in Step 1; rather than
specifying a connection string you are simply prompted to browse to the Access Accessing data directly from an ASP.NET Web page is usually a poor idea for anything but the most trivial Web applications. Ideally you'll separate your application into different layers: a presentation layer (the ASP.NET pages), a data-access layer (classes designed for working with the underlying data store), and a data layer (the actual data store, the stored procedures, and the data model). The ObjectDataSource allows you to declaratively work with data retrieved from middle-tier objects. With the ObjectDataSource you simply specify the type of the object to use and the method names for selecting, inserting, updating, and deleting data. For more information be sure to read Stephen Walther's article Working with the ASP.NET 2.0 ObjectDataSource Control.
Conclusion At the time of this writing (December 2004), ASP.NET 2.0 is still in Beta 1, with Beta 2 expected to be released in Q1 2005. You can download the latest versions of the Beta at http://labs.msdn.microsoft.com/. UPDATE: As of November 2005, ASP.NET 2.0 is out of Beta and officially released. You can learn more about ASP.NET 2.0 at the 2.0 article index here on 4Guys; for more on working with data, check out the Accessing and Updating Data in ASP.NET 2.0 article series. Happy Programming!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|