specifying datavaluefield in ddlb

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
 
M

Mike

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
 
G

Guest

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top