Accessing and Updating Data in ASP.NET 2.0: Customizing the Editing Interface
Posted by: 4GuysFromRolla.com Headlines,
on 08 Aug 2007 |
View original | Bookmarked: 0 time(s)
| A Multipart Series on ASP.NET 2.0's Data Source Controls |
|---|
ASP.NET 2.0 introduced a number of new Web controls designed for accessing and modifying data.
These controls allow page developers to declaratively access and modify data without writing any
code to perform the data access. This article is one in a series of articles on ASP.NET 2.0's new data
source controls.
Data Source Control Basics - explores the concepts
and advantages of data source controls, and compares their usage in ASP.NET 2.0 to data access techniques in ASP.NET 1.x.Accessing Database Data - shows how to use the
SqlDataSource and AccessDataSource controls to query data from a relational database.Filtering Database Data with Parameters - learn how to
retrieve just a subset of database data based on hard-coded values and values from the querystring, other Web controls on the page,
session variables, and so on.Retrieving XML Data with XmlDataSource Control - see how
to retrieve both remote and local XML data and display it in a data Web control.Creating Custom Parameter Controls - learn how
to create your own custom, declarative Parameter controls for use in the data source controls' parameters collections.Examining the Data Source Control's Events - explore the
events raised during a data source control's lifecycle.Declaratively Caching Data - learn how to cache data
to the data cache simply by setting a couple of data source control properties.Programmatically Accessing Data using the Data Source Controls -
programmatically retrieve, insert, delete, and update data using the SqlDataSource and AccessDataSource controls.Inserting Data - learn how to insert data using
a SqlDataSource control. Also examines how to retrieve the IDENTITY column value for the just-inserted record.Deleting Data - see how to delete data using
a SqlDataSource control. Also looks at how to programmatically cancel a delete.Updating Basics - learn the basics of updating database data using a
SqlDataSource control. Also examines using the GridView to provide a web-based editing interface.Customizing the Editing Interface - see how to
customize the GridView's columns to provide a customized editing interface that includes input validation and alternative
user interface elements.
(Subscribe to this Article Series!
) |
In the last installment of this article series, Updating
Basics, we looked at how to configure the SqlDataSource control to issue UPDATE statements to a database.
We then saw how the GridView control can work in tandem with the SqlDataSource control to provide a simple web-based
editing interface composed of textboxes for each data field. While this simplified interface enabled developers to create an
editable interface with zero code and just a few clicks of the mouse, the interface is so simple that it is impractical for
all but the most trivial scenarios. Some of these limitations were exhibited in the Updating Basics article when attempting to
update a product's Category. In short, you had to modify the product's CategoryID value, meaning that to
change a product's category from Beverages to Dairy you would have to change the CategoryID value from 1 to 4.
Likewise, the simplified interface lacks any input validation that may be necessary when editing required fields or fields
that must appear in a particular format (like dates or numbers).
Fortunately, the GridView's editing interface can be customized to include validation controls and alternative user interface
elements. It requires a little more effort, but in most cases these changes can be completed entirely through the
Designer or the page's declarative markup. In this installment we will extend the simplified editing interface from
Updating Basics to include validation controls for the ProductName and UnitPrice fields; we will
also replace the CategoryID data field's textbox with a drop-down list that enumerates the possible categories.
Read on to learn more!
Read More >