Binding Data to Controls
(Page 1 of 4 )
Looking for a way to writer fewer lines of code while streamlining your ASP.NET application? This article, the first of two parts, shows you one way to do this. It is excerpted from chapter 12 of
ASP.NET 2.0 DeMYSTiFieD, written by Jim Keogh (McGraw-Hill/Osborne; ISBN: 0072261412).
Developers are always looking for efficient ways to streamline an application and reduce lines of code to write. One of those ways is to link data directly to a web control so that it appears automatically every time the web page is displayed.
Linking data to a web control is called data binding and is the topic of this chapter. Data can come from a variety of sources, but the most common source is from a database. In this chapter, you’ll learn how to bind data to a web control and then use that data and web control within your application.
Data Binding Basics
In previous chapters you learned how to retrieve information from a database and display the information on your web page. Many times this information is displayed in a control such as a drop-down list box or a text box on a web form.
You can dynamically assign information from a database to a control by using a process called data binding. Data binding links the value property of a control to a data source while your application is running. The data source can be data from a database. The data source can also be an expression, methods, or properties of another control.
Each control has a DataSource property that specifies the source of the data for the control. Each control also has a DataBind() method. You call the DataBind() method whenever you want to bring the data source into the control.
Throughout this chapter we’ll show how to bind data from a database to a Repeater control, a drop-down list control, a radio button control, and a list box control.
Next: The Repeater Control >>
More ASP.NET Articles
More By McGraw-Hill/Osborne
|
This article is excerpted from chapter 12 of ASP.NET 2.0 DeMYSTiFieD, written by Jim Keogh (McGraw-Hill/Osborne; ISBN: 0072261412). Check it out today at your favorite bookstore. Buy this book now.
|
|