DropdownList: How to select by value programaticly?

N

Northern

I have an ASP DropdownList populated. What I want is to
select a new item, in my code, by set a datavale to
dropdownlist's selectedItem.Value property. I did the
following:

MyDropdown.SelectedItem.Value = "value 1"

Even though the "value 1" is in the dropdownlist's data
value collection, the dropdown's datatext doesn't change.

What am I doing wrong here? How should I do this?

Please help!
 
R

Rajeev Soni

You should say

MyDropdown.SelectedIndex = <Index of the Item you want to select.>

Rajeev
 
N

Northern

Thank you so much Ken. That's exactly what I need.
You are the MVP!

Thank a million!
 
K

Ken Cox [Microsoft MVP]

Glad to hear that it worked for you!

Ken

Thank you so much Ken. That's exactly what I need.
You are the MVP!

Thank a million!
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top