O'Reilly logo

Programming ASP .NET by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. In order 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 language 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 the previous chapter, 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="-- ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required