specifying datavaluefield in ddlb

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a dropdown of states that is populated from a table, that looks like
ddlb.DataValueField="StateCode" // ex: FL
ddlb.DataTextField="StateDescription" // ex: Florida

If I want to set the initial value I can use
ddlb.SelectedValue="Florida"
In other words, SelectedValue is the DataTextField

How do I set the initial value to the DataValueField?
ddlb.SelectedValue="FL" doesnt work (or is it just me?)

Thanks, Mark
 
try this:
dd.SelectedItem.Text = "FL";

or if you know the index number of Fl you can do

dd.SelectedIndex = 5 (or whatever FL is)

Mike
 
Actually, SelectedItem.Value is closer to what I want. But it adds a new
entry at the top, rather than selecting the existing value of "FL"

In other words, I get :
<option value="FL" selected="selected" value="FL">Alabama
<option value="AL">Alabama
.... other states
<option value="FL">Florida

And what I want is:
<option value="FL" selected="selected">Florida
<option value="AL">Alabama
.... other states
 
Back
Top