asp.net.ph

HtmlSelect.Value Property

System.Web.UI.HtmlControls Namespace   HtmlSelect Class


Returns the value of the selected item in the HtmlSelect control.

Syntax


Script string strVar = HtmlSelect.Value

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


strVar String object that will contain the value of the selected item in the HtmlSelect control.

The property is read/write with no default value.

Remarks

The Value property is mainly used to determine the value of the selected item in a single-selection HtmlSelect control. If an explicit Value attribute is associated with the selected option element, this property returns that value; otherwise, it returns the text of the selected item.

If multiple selection is enabled, this property returns only the value of the first selected item. To determine the values of multiple selected items, you need to iterate through the Items collection and test the ListItem.Selected property of each option item.

You can also set this property to a string that specifies the item to be selected in the control.

HtmlSelect.Value = strValue

If you set this property, the SelectedIndex property is updated with the index of the first item in the list that matches the specified value. If no match is found, the SelectedIndex property is left unchanged.

To be submitted with the data associated with a <form>, each of the form input controls must have a Name and a valid Value. Only controls with a valid name/value pair are sent with the HTTP Request message to the receiving program for processing.

These name/value pairs are then accessible on the server via the Request.Params, Request.Form, or Request.QueryString collections.

When multiple selection is enabled, the above Request class collections return a comma-separated list of the selected values.

Example

The following example illustrates using the Value property to determine the selected option in an HtmlSelect.

 Show me 

This example retrieves the selected options in an HtmlSelect submitted with a form using POST, by looping thru the Request.Form collection.

 Show me 

This example retrieves the selected options in an HtmlSelect submitted with a form using GET, by looping thru the Request.QueryString collection.

 Show me 

See Also

HtmlSelect Members   Name Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph