System.Web.UI.HtmlControls Namespace HtmlSelect Class
Returns the value of the selected item in the HtmlSelect control.
Script |
string strVar = HtmlSelect.Value |
This property can only be used programmatically; it cannot be set when declaring the control.
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.
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.
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
HtmlSelect Members Name