Dropdown List

Another option for allowing a user to select a single option from a group of options is using the <select> tag. This tag creates a dropdown list box from which the user can select a single value. You can use the HTMLSelect control to implement the <select> tag. The <select> tag is also useful when you have a large number of options and little space to display the options.

To fully leverage this control, you could use the data-binding capabilities. For example, if you have an array of values, you can bind to this array by using the

REQUEST INPUT FROM A DROP-DOWN LIST

Datasource property and the DataBind method of the HTMLSelect control.

When creating the HTMLSelect control programmatically, you can use the selectedindex attribute to specify which option the user sees when the list box appears. If this is not set, the first option displays. If you want to enable users to select more that one item from the list, you can include the controls multiple attribute and set it equal to true.

Like the HTMLlnputRadioButton control, you can ask questions which have multiple options for answers and allow only one of the options to be chosen.

4 Untitled - Notepad

File Edit Format Help jsjxi

^SCRIPT LANGUAGE-'C#" RUNAT-'Server"?

void SubmitBtn_Click(object Source, EventArqs e) { spanMessage.lnnerHtml-'Your suggestion is..." + selectSuggestions,Value -

«FONT FACE-'Verdana"?

«H3?Welcome to mylifetimegoals.com«/H3? What suggestions do you have for improving our site?

«FORM RUNAT-'Setver"?

SELECT ID="selectSuggestions" RUNAT="Server"> «OPTION?Fewer Goals«/OPTION? «OPTION?More Goals«/OPTION? «OPTION?Same Number of Goals«/OPTION? «/SELECT?

INPUT TYPE-'Submit" VALUE-'Submit" OnServerClick-'SubmitBtnjClick" RUNAT-'Server"?

Q Open the

SuggestionsTemplate.aspx template from the Code Templates directory.

Add an HTMLSelect control and a number of options to the form.

< Add the code in the SubmitBtn_Click function to send an appropriate message back to the user.

□ Save the file and request it from the Web server.

0 Click H and select the first option from the dropdown list.

□ Save the file and request it from the Web server.

Note: See pages 20 to 25 for instructions on saving a file to the Web server and then requesting the file using the IIS Admin.

0 Click H and select the first option from the dropdown list.

-0 Click the Submit button.

-■ A message appears displaying the suggestion.

Was this article helpful?

0 0

Post a comment