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.
For this lesson I have created the ADO.NET Entity Data Model shown in Figure 20A-1.
Figure 20A.1. FIGURE 20A-1
This is the markup for a
<asp:GridView ID="GridViewTasks" runat="server" DataSourceID="EntityDataSourceTasks"> </asp:GridView>
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
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