Selecting DDL item based on TEXT? Why isn't this working?

D

darrel

I have a DDL list along these lines:

item value="1" text="a"
item value="2" text="b"
item value="3" text="c"
item value="2" text="d"
item value="2" text="e"
item value="1" text="f"
item value="1" text="g"

The data I'm retrieving from the database maps to the TEXT field of the
items. So, if the data is 'g' I want to preselect the 7th item in the list
above.

I'm using this:

ddl_county.SelectedIndex =
ddl_county.Items.IndexOf(ddl_county.Items.FindByText(Trim(tablerow("jurisdiction"))))

But what it's doing is preselecting the first item that has the same value
as the item with the text I'm looking for. For instance, if the data is 'g',
it's selecting 'a'. If the data is 'e', it's selecting 'b'.

The above statement SEEMS to make sense, but I'm obviously not understanding
the logic fully. Can anyone point out the error of my logic?

-Darrel
 
D

darrel

Can you try:
ddl_county.Items.FindByText(Trim(tablerow("jurisdiction"))).Selected =
True

That fixes the problem of preselecting!

But now I'm having the opposite problem...trying to save the data. I was
using this to grab the text of the selected item:

ddl_county.SelectedItem.Text
But what it is doing is selecting the text of the first ITEM that has the
same VALUE as the VALUE of the item that matches the currently selected
item.

Ie:
ITEM VALUE="1" TEXT="a"
ITEM VALUE="2" TEXT="b"
ITEM VALUE="1" TEXT="c"

If the third item is selected, the ddl_county.SelectedItem.Text sends the
text 'a' to the database. Why is that?

-Darrel
 
B

bruce barker

you can not use dup values in a ddl or <select>. the browser only posts
back the selected value(s), so there is no way to determine the matching
text.

-- bruce (sqlwork.com)
 
D

darrel

you can not use dup values in a ddl or said:
back the selected value(s), so there is no way to determine the matching
text.

Really!?

Wow. I never knew that. I suppose I should have. OK, well, that resolves
that issue. Thanks for the info!

-Darrel
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top