Adding Controls

Before proceeding, delete the line that tells the time from your aspx page, so that you can start the next part clean. In fact, that is the last time you'll mix HTML and code; from now on you'll add controls to the aspx page, and code in the code-behind (aspx.vb) page.

You can add server-side controls to a web form in three ways: by dragging controls from the Toolbox to the Design page, by writing HTML into the source page, or by programmatically adding them at runtime. For example, suppose you want to use buttons to let the user choose one of three shippers provided in the Northwind database. To do so, click on Design view, and drag a RadioButtonList control onto the form, as shown in Figure 8-10.

Drag a RadioButtonList onto the form

Figure 8-10. Drag a RadioButtonList onto the form

Once the RadioButtonList control is on your form, click its smart tag and choose Edit Items to add items to the list, as shown in Figure 8-11.

Edit items in RadioButtonList

Figure 8-11. Edit items in RadioButtonList

The ListItem Collection Editor opens. Click the Add button to add a List Item. Type in Text (e.g., "Speedy Express") and for the first item set Selected to True (to select the first radio button in the list). Add entries for "United Package" and for "Federal Shipping," as shown in Figure 8-12.

When you click OK, the three buttons appear in the ...

Get Programming Visual Basic 2005 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.