ASP.NET includes a number of data source and data Web controls that make it remarkably easy to work with data from a web page. For example, to display
the results of a database query simply add and configure a SqlDataSource control and then bind that to a GridView, ListView,
or some other data Web control. There's no need to write any source code; the data source controls allow declarative access to data. For more information
on working with data in ASP.NET see my Accessing and Updating Data in ASP.NET
article series and Working with Data tutorials.
The GridView and ListView controls are great for displaying a set of records, while the DetailsView and FormView controls are ideal for displaying
information about a single record. There are times where we only need to display a single column from a single record. While you can certainly
use the DetailsView or FormView controls for this, it would be easier to use a Label Web control. However, the Label control does not natively
support data binding. As a result, to display a database needed in a Label Web control you need to write code (or put the Label in a
FormView templates or a DetailsView TemplateField).
The good news is that the .NET Framework offers appropriate base classes that we can extend to build a databound Label Web control.
This article shows how to create and use such a control. The control, which I named DataboundLabel, and its complete source code is available for
download at the end of this article, along with a demo of the control in use. Read on to learn more!
Read More >