Chapter 9. Data Binding
Nearly every ASP.NET application displays data of some sort, either from a database or from other data sources. Data binding allows you to create a relationship between a control (such as a list box or data grid) and a source of data (such as SQL Server). ASP.NET takes care of the details of displaying the data in your control.
You can bind to any data source, including such simple sources as
properties, expressions, or the result of a method call, and such
complex sources as arrays, collections, and databases. For controls
that display a collection, such as a list box or data grid, you must
bind to a source which implements the ICollection
interface. This allows ASP.NET to iterate the collection and display
each member in turn.
ArrayList
Later chapters will focus on binding to databases, since that is the common case for serious ASP.NET development. To focus on the mechanics of data-binding, however, this chapter starts simple, by binding controls to an ArrayList rather than to data from a database. Visual Basic .NET, C#, and most other programming languages support the array, an ordered collection of objects, all of the same type. An ArrayList is a .NET Framework collection that acts as an expandable array.
In Chapter 8, you created a drop-down list box that contained the titles of some of my books on programming. The relevant portion of the HTML source appeared as follows:
<ASP:DropDownList id=ddlBooks runat=server> <asp:ListItem Value="-- Please Pick A ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access