A Quick Example of Using Data Source Controls

You need three items to work with the Web Forms data controls: some data, a data source control, and a data-bound UI control.

To begin, create a new Visual Studio project named WebApp using the Empty ASP.NET Application template and add a new Web Form called Default.aspx. All of the examples in this chapter will be added to this page.

Creating the Data

You can use a range of different data types with Web Forms, but we are going to start with the simplest—some objects contained in a class. In the code-behind file, Default.aspx.cs, define a new data type called Fruit and create an array of Fruit objects in the Default code-behind class, as shown in Listing 18-1.

Listing 18-1. Creating some data

using ...

Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.