4.3. Introducing the FormView Control

The preceding sections of this chapter demonstrate the easy implementation of RUD (Retrieve, Update, Delete), using the GridView control. For the adding (Creating in CRUD-parlance) part of the acronym, you use ASP.NET's FormView control.

Oh, and have you written any code yet? Keep it that way!

4.3.1. Adding a FormView control to the page

The FormView control lets you display, update, and add data via drag and drop. In this procedure, you only need the FormView control's ability to insert (that is, add) a row. Remember: You're still working on the ASP.NET page that you added in Chapter 3.

Follow these steps to add a FormView control to the page and set its data source:

  1. From the Toolbox, in the Data category, drag a FormView control and drop it below the existing GridView control.

  2. Click the Smart Tasks arrow thingy to open the FormView control's Tasks menu.

  3. Choose a data source (usually, SqlDataSource1) from the drop-down list, as shown in Figure 4-7.

Figure 4-7. Choosing the source of data for the FormView control.

As configured, the FormView control does more than you need on this page, such as displaying and updating DVD data. In the following section, you strip out the unwanted functions by digging into the FormView control's templates.

4.3.2. Changing the FormView control's templates

The FormView control is a shape-shifter in that it can ...

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.