Gets the value of the selected item in the list control, or selects the item in the list control that contains the specified value.
a string
This property returns the ListItem.Value property of the selected System.Web.UI.WebControls.ListItem. The ListControl.SelectedValue property is commonly used to determine the value of the selected item in the list control. If multiple items are selected, the value of the selected item with the lowest index is returned. If no item is selected, an empty string ("") is returned.
The ListControl.SelectedValue property can also be used to select an item in the list control by setting it with the value of the item.
This property cannot be set by themes or style sheet themes. For more information, see System.Web.UI.ThemeableAttribute and ASP.NET Themes Overview.
When the selected value is not in the list of available values and a postback is performed, an ArgumentOutOfRangeException exception is thrown. The following example shows how to catch an invalid value before postback occurs:
Example
Me.DropDownList1.Items.Add(New ListItem( Text="Hello", Value="1" )) If DropDownList1.Items.FindByValue("2") IsNot Nothing Then Response.Write("Found") End If
Example
this.DropDownList1.Items.Add(new ListItem{ Text="Hello", Value="1" }); if(DropDownList1.Items.FindByValue("2") != null) { Response.Write("Found"); }