Accessing and Updating Data in ASP.NET 2.0: Creating Custom Parameter Controls
Posted by: 4GuysFromRolla.com Headlines,
on 01 Nov 2006 |
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.
(Subscribe to this Article Series!
) |
As discussed in previous installments of this article series, ASP.NET 2.0
ships with a number of built-in data source controls
that can be used to programmatically access data (the SqlDataSource, ObjectDataSource, XmlDataSource,
and so on). The SqlDataSource and ObjectDataSource commonly return or modify data based upon parameters. For example,
a SqlDataSource might use a parameterized query, like SELECT * FROM TableName WHERE ColumName = @parameterName;
the ObjectDataSource's parameters are those expected input parameters to the methods it invokes.
In either case, the values of the parameters can be specified using Parameter controls.
(See Filtering Database Data with Parameters installment
for more information on using parameters with the data source controls.)
A Parameter controls is a control whose purpose is to provide a value for a given parameter. ASP.NET 2.0 ships with
seven Parameter controls - the generic
ControlParameter and
the more specific
ControlParameter,
CookieParameter,
FormParameter,
ProfileParameter,
QueryStringParameter,
and SessionParameter controls -
which pull their values from web controls on the page, session state, querystring fields, and so on.
If you need to use a value that's not provided by one of the specific Parameter controls, you can use
the generic Parameter control and set its value programmatically (a topic we'll address in a future article
in this series). Alternatively, you can create a customParameter control that grabs the specific data
you need. Creating such a custom Parameter control is quite easy and straightforward, as we'll see in this
article. Read on to learn more!
Read More >