Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Want to programmatically set a dropdownlist selected value to a saved value - with a twist

Avatar of taduh
taduhFlag for United States of America asked on
Visual Basic Classic.NET ProgrammingASP.NET
22 Comments1 Solution708 ViewsLast Modified:
Hi Experts,

I want to programatically set a DDL's selected value to a value I have saved in a variable. For instance, if the selected value was "Cincinnati", I have, in the past, saved it to a string variable, say SvCity, then at a later point in the program (when the Selected Value could have changed) I reset it to "Cincinnati" using DDL.SelectedValue = SvCity.  

Here's the twist though - This is a dynamic drop-down list populated from an SQL table that could be changing. "Cincinnati" may noy even be in the list when I go back, so I need to check to see if the DDL contains "Cincinnati" before I try to set the Selected Value to it.

Now, I'm trying to use the Contains parameter of the DDL to see if it contains the saved value, but in order to do so, I have to make the variable in which I save the value a ListItem. The problem is that I'm getting a syntax error when I try to set that variable equal to a string or  a textbox value or even to DDL.SelectedValue.

Is there a way around this? Is there a better way to do this?

Thanks,

taDUH
ASKER CERTIFIED SOLUTION
Avatar of taduh
taduhFlag of United States of America imageFinancial Systems Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 22 Comments.
See Answers