|
|
|
start date: Thu, 16 Aug 2007 15:22:30 -0500,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
darrel
|
|
2
Mark Rae [MVP]
|
|
3
darrel
|
|
4
bruce barker
|
|
5
darrel
|
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.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
Date:Thu, 16 Aug 2007 15:22:30 -0500
Author:
|
Re: Selecting DDL item based on TEXT? Why isn't this working?
"darrel" wrote in message
news:%23SABtME4HHA.3600@TK2MSFTNGP02.phx.gbl...
> Can anyone point out the error of my logic?
Can you try:
ddl_county.Items.FindByText(Trim(tablerow("jurisdiction"))).Selected = True
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Thu, 16 Aug 2007 21:32:47 +0100
Author:
|
Re: Selecting DDL item based on TEXT? Why isn't this working?
> 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
Date:Thu, 16 Aug 2007 16:03:44 -0500
Author:
|
Re: Selecting DDL item based on TEXT? Why isn't this working?
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.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
>
>
Date:Thu, 16 Aug 2007 15:04:40 -0700
Author:
|
Re: Selecting DDL item based on TEXT? Why isn't this working?
> 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
Date:Fri, 17 Aug 2007 10:15:40 -0500
Author:
|
|
|