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

  • Thread starter Thread starter darrel
  • Start date Start date
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
 
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
 
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)
 
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
 
Back
Top