O'Reilly logo

ASP.NET 4 24-Hour Trainer by Toi B. Wright

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 20A. Using GridView in Web Forms

The GridView control is one of the most useful yet complex server controls provided by Web Forms. Nothing like it exists in the MVC framework (unless you write your own). In this lesson I show you how to use the GridView control to display, select, sort, page, and edit data.

FORMATTING THE GRIDVIEW

For this lesson I have created the ADO.NET Entity Data Model shown in Figure 20A-1.

FIGURE 20A-1

Figure 20A.1. FIGURE 20A-1

This is the markup for a GridView named GridViewTasks:

<asp:GridView ID="GridViewTasks" runat="server"
    DataSourceID="EntityDataSourceTasks">
</asp:GridView>

Note

I cover the DataSourceID later in this lesson.

Figure 20A-2 shows the page that is rendered using the preceding GridView markup.

FIGURE 20A-2

Figure 20A.2. FIGURE 20A-2

The page shows a grid that lists all of the records in the table. However, the grid looks incredibly plain. The easiest way to jazz up the appearance of a GridView control is to select the AutoFormat option from the GridView Tasks smart tag (see Figure 20A-3) to open the AutoFormat dialog box (see Figure 20A-4). The AutoFormat dialog box allows you to preview a number of professionally designed formats. Click the Apply button to apply the selected format.

Figure 20A.3. FIGURE 20A-3

Figure 20A.4. FIGURE 20A-4

This is the markup for the GridView ...

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