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 wit
Use this...
protected void Page_Load(object sender, EventArgs e)
{
string t = "test";
drpFunction.SelectedItem.Text = t;
}
or
protected void Page_Load(object sender, EventArgs e)
{
string t = "test";
drpFunction.SelectedItem.Value = t;
}
this is proper way.......
Setting the itm.Selected = true; only works if you drp.ClearSelection() first. I prefer the following:
drpFunction.SelectedValue = drpFunction.Items.FindByText(t).Value;