tags:

views:

85

answers:

3

I'm using an ASP.NET dropdown. I want to set the selected element using an ID (Id) which is stored in the DataValue field.

ddlTest.DataValueField = "Id";    
ddlTest.DataTextField = "Name";
ddlTest.DataSource = searchResultList;
ddlTest.DataBind();

But all I can see is the SelectedIndex property which isn't the correct thing. How do I set by value?

+3  A: 

After it's bound you can set the SelectedValue property to the correct id.

orthod0ks
A: 

If you need the text of the selected item then you can use

dropdwonlistID.SelectedItem.Value // selecting value of the selected item
dropdwonlistID.SelectedItem.Text // selecting displayed text of the selected item
rahul
+1  A: 

ddlTest.selectedValue = [whatever value you want to set];

Bhaskar