I am working on an Asp.NET project and I am trying to set the selected value of a dropdown list with a text property. For example i have i.e an item in the dropdown list with text test
. Programmatically can i set it to selecteditem
by Text
?. I am using the follwing code but is not working.
protected void Page_Load(object sender, EventArgs e)
{
string t = "test";
drpFunction.Text = t;
}
But is not working. Any suggestions ?
Use this...
or
this is proper way.......
This Link might help you
This works in Web
This also works fine.
The SelectedValue property can be used to select an item in the list control by setting it with the value of the item. However, an exception will be thrown during postback if the the selected value doesn't match the list of values in the dropdown list.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue(v=vs.110).aspx