Hour11.Collecting Input Using Drop-down Lists, Radio Buttons, and Check Boxes






Summary

In this hour we examined three Web controls commonly used to collect user input: the DropDownList, RadioButton, and CheckBox Web controls. These Web controls are typically used when the user's input is restricted to either a subset of available options or just one of two options.

For example, if the user is asked to specify the time zone he lives in, a DropDownList Web control could be used that contains the various time zones in the world, from which the user can choose one. Another example is when a user is asked a yes/no question, which is common in online surveys. For such a question, a CheckBox Web control can be used.

In examining the DropDownList Web control, we saw that it has a number of list items, which are the options from which the user can select one. When adding a DropDownList Web control to an ASP.NET web page, we need to explicitly specify those list items that should appear in the drop-down list. Fortunately, this is a simple task through Visual Web Developer's ListItem Collection Editor dialog box (refer to Figure.5). In the ASP.NET source code portion, the list item that was selected can be determined by the DropDownList Web control's SelectedItem property.

Like drop-down lists, radio buttons allow the user to select one option from a series of options. Specifically, a radio button is needed for each option, and these radio buttons must be made mutually exclusive with one another so that the user can select only one radio button from the group of related radio buttons.

The RadioButton Web control creates a single radio button. To denote that multiple RadioButton Web controls should be considered related (so that the user can select only one radio button from the related radio buttons), we use the GroupName property. We can use the RadioButton Web control's Checked property to determine whether the user selected a particular RadioButton Web control's corresponding radio button.

With radio buttons and drop-down lists, the user can choose only one option from a list of options. A list of check boxes, however, permits the user to choose multiple options. To create a check box, we use the CheckBox Web control. Like the RadioButton, the CheckBox Web control has a Checked property that indicates whether the check box was selected.

Now that we've examined the Web controls for collecting user input, we're ready to learn how to ensure that the input entered is valid. Typically, when we're collecting user input, the input must be of a certain format or within certain constraints. For example, if users are prompted to enter their age, the value entered should be numeric and within an acceptable range (say 0 to 110). In the next hour we'll examine ASP.NET's validation Web controls, which are Web controls designed to validate input data.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows