This property returns the Value property of the selected ListItem. The 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 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 ThemeableAttribute and ASP.NET Themes and Skins Overview.
When the selected value is not in the list of available values and a postback is performed, an ArgumentOutOfRangeException is thrown. The following example shows how to catch an invalid value before postback happens:
Me.DropDownList1.Items.Add(New ListItem( Text="Hello", Value="1" ))
If DropDownList1.Items.FindByValue("2") IsNot Nothing Then
Response.Write("Found")
End If
this.DropDownList1.Items.Add(new ListItem{ Text="Hello", Value="1" });
if(DropDownList1.Items.FindByValue("2") != null) {
Response.Write("Found");
}