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?