Question: How set dropdownlist SelectedIndex based on value?

V

VB Programmer

I have a dropdownlist. It consists of these Name/Value pairs:
"Apple","1"
"Banana","2"
"Pear","3"

The value (number) is stored in the database.

How can I set the dropdownlist to the correct SelectedIndex based on the
value I retrieve from the db?

Thanks!
 
C

Cliff Harris

the Items collection in the DropDownList control has a member function
called FindByValue that you can use:

int i = GetIntFromDB();
myDropDown.Items.FindByValue(i).Selected = true;

HTH,
-Cliff
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top