469,631 Members | 1,313 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

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

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.FindByTe xt(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
Aug 16 '07 #1
4 1925
"darrel" <no*****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Can anyone point out the error of my logic?
Can you try:
ddl_county.Items.FindByText(Trim(tablerow("jurisdi ction"))).Selected = True
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 16 '07 #2
Can you try:
ddl_county.Items.FindByText(Trim(tablerow("jurisdi ction"))).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
Aug 16 '07 #3
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)

darrel wrote:
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.FindByTe xt(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

Aug 16 '07 #4
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.
Really!?

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

-Darrel
Aug 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by David Anderson | last post: by
3 posts views Thread by larry mckay | last post: by
3 posts views Thread by KatMagic | last post: by
16 posts views Thread by Vikas Kumar | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.