How do I programmatically select and highlight a selection in a drop down list

K

Karl Seguin

myDropDownList.SelectedItem =
myDropDownList.Items.IndexOf(MyDropDownList.Items.FindByValue(myString))

Karl
 
J

John Morgan

I am using a database to populate a drop down list using

myDropDownList.DataSource = myCmd.ExecuteReader
myDropDownList.DataBind()

That works alright and a few lines later in the code I wish to
select and highlight one of the items in the list. I have tried what I
think are all the alternatives eg
selectedvalue=myString but I cannot find anything that works.

I would be grateful for some help,

Best wishes, John Morgan
 
G

Guest

This would also work.

ListItem li = myDropDownList.Items.FindByValue(myValue); // You can also use .FindByText(myText)
if(li != null) li.Selected = true;

Suresh.

----- John Morgan wrote: -----


I am using a database to populate a drop down list using

myDropDownList.DataSource = myCmd.ExecuteReader
myDropDownList.DataBind()

That works alright and a few lines later in the code I wish to
select and highlight one of the items in the list. I have tried what I
think are all the alternatives eg
selectedvalue=myString but I cannot find anything that works.

I would be grateful for some help,

Best wishes, John Morgan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top