3.3. Generating a Data-Driven Web Page

Did you notice that the heading says Generating rather than Programming? In this section, VWD generates tons of code as you drag and drop.

3.3.1. Adding a single file model Web page

First, you need to create a page so you have a place for the code it creates. For this simple project (and most of the examples in this book), you use the single file model where everything goes into the .aspx page. See the "Choosing single file model or code-behind" sidebar to decide which is right for you. To add a Web page that uses the single file model, follow these steps:

  1. In Solution Explorer, right-click the project name, and then choose Add New Item.

  2. In the Add New Item window, select the Web Form template.

  3. Type default.aspx as the name of the file.

  4. Clear the check box for Place Code in Separate File.

    This ensures that the IDE puts all code within the .aspx file.

  5. Click Add.

    The new, empty page appears in the IDE.

3.3.2. Using the database to build a Web page

Instead of adding controls to the page from the Toolbox, let the IDE do the work. You need a SQL Server database (Express is fine) for this magic. I show you how to create the database in the previous section, "Using a SQL Server Express Database." To generate a user interface based on a database table, follow these steps:

Choosing single file model or code-behind

ASP.NET allows you to keep both the HTML and Visual Basic (or C#) source code in one file that uses the .aspx extension. The other option is ...

Get ASP.NET 3.5 For Dummies® 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.