13.2. Rolling Your Own with the ListView Control

Some developers felt that the ASP.NET data controls were, er, too controlling. For example, programmers like the way the GridView handles data editing, deleting, and paging, but (and there's always a "but!") they complain that it locks the data inside HTML tables.

The ASP.NET team responded with the ListView control, which doesn't dictate the HTML. It's up to you to create the HTML markup — prepare to get your hands dirty!

This section walks you through the creation of the data-driven page shown in Figure 13-4. You create CSS-friendly markup (no tables) for the ListView.

Figure 13-4. A CSS-friendly ListView built from scratch.

13.2.1. Generating the DataContext

The DataContext is a set of data classes that let ASP.NET code believe that it's dealing with objects rather than database tables and fields. A VWD designer maps objects to database tables. You make quick work of generating the DataContext by following these steps:

  1. In Solution Explorer (ViewSolution Explorer) add the JulieDVD.mdf database (created and configured in Chapter 3) to the project's App_Data folder.

  2. Add a LINQ to SQL Classes file named juliedvddataclasses.dbml (FileNew FileLINQ to SQL ClassesAdd) to the project.

    Visual Web Designer offers to create the App_Code folder ...

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.