[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Finding an index in a dataset and setting SelectedIndex on dropdownlist

wrecker

2/9/2004 10:46:00 PM

Hi all,

I have a dataset bound to a dropdownlist and I'm trying to get the
dropdownlist to start off with a default value selected (not the first
value). Is there any way that I can retrieve the index of the item I
want from the dataset and use this to set the SelectedIndex of the
dropdownlist? I've tried creating a dataview from the dataset and
sorting it and then using the return value of DataView.Find() method
to set the index but it doesn't seem to set the index correctly
(probably because it is now sorted?). Is the only way to iterate
through the dataset until I find the row I want?

Thanks

Rene
3 Answers

Wardeaux

2/13/2004 10:07:00 PM

0


I've found I have this to work well for me:

make sure this is AFTER you call MySel.Databind() to load the DropDownList

1) MySel.SelectedIndex =
MySel.Items.IndexOf(MySel.Items.FindByText(strToFind.ToUpper()))
or
2) you can set the VALUE of each item to Upper case when loading the
DropDownList and then
MySel.SelectedIndex =
MySel.Items.IndexOf(MySel.Items.FindByValue(strToFind.ToUpper()))

Hope this helps!
wardeaux

"wrecker" <wrecker@wrecked.com> wrote in message
news:i03g20tjj7jmv6f0sclttmb6kk54ljri8p@4ax.com...
> Hi all,
>
> I have a dataset bound to a dropdownlist and I'm trying to get the
> dropdownlist to start off with a default value selected (not the first
> value). Is there any way that I can retrieve the index of the item I
> want from the dataset and use this to set the SelectedIndex of the
> dropdownlist? I've tried creating a dataview from the dataset and
> sorting it and then using the return value of DataView.Find() method
> to set the index but it doesn't seem to set the index correctly
> (probably because it is now sorted?). Is the only way to iterate
> through the dataset until I find the row I want?
>
> Thanks
>
> Rene


Fred J. McCall

7/26/2009 1:15:00 AM

0

Ian Smith <ianinhoose@btinternet.naespam.com> wrote:

:On Sat, 25 Jul 2009 10:43:42 -0700, Fred J. McCall wis temporarily glaikit
:then blurted oot this wisdom:
:
:> Ian Smith <ianinhoose@btinternet.naespam.com> wrote:
:>
:> :On Fri, 24 Jul 2009 09:50:05 -0400, conwaycaine wis temporarily glaikit
:> :then blurted oot this wisdom:
:> :
:> :> "Fred J. McCall" <fjmccall@gmail.com> wrote in message :>
:> news:2n8i65hgf52fgugdbtg87d32iok7iuflbt@4ax.com... :>> Ian Smith
:> <ianinhoose@btinternet.naespam.com> wrote: : :>> :Didn't the Picts eat a
:> Roman legion, or something like that? Now where :>> :did I read that
:> story....
:> :>> :
:> :>>
:> :>> So what's wrong with eating Italian? :>
:> :> Too much garlic..........
:> :
:> :And they might have relatives in Sicily. :
:>
:> Don't be Corse...
:
:Messina lot of puns in here recently. Maybe it's the weather?
:

Well, when in Rome...

conwaycaine

7/26/2009 2:06:00 PM

0


"Malcolm" <Malcolm@indaal.demon.co.uk> wrote in message
news:IPrTGeJVyxaKFwSJ@indaal.demon.co.uk...
>
> In article <eeydnScxWYL4hfbXnZ2dnUVZ_h6dnZ2d@giganews.com>, conwaycaine
> <conwaycaine@bellsouth.net> writes
>>
>>"Ian Smith" <ianinhoose@btinternet.naespam.com> wrote in message
>>news:4a6ac2d0$0$11306$166caa5@unlimited.newshosting.com...
>>> On Wed, 22 Jul 2009 09:25:19 -0400, conwaycaine wis temporarily glaikit
>>> then blurted oot this wisdom:
>>>
>>>> "Ian Smith" <ianinhoose@btinternet.naespam.com> wrote in message
>>>> news:4a661837$0$14997$776ccb5@unlimited.newshosting.com...
>>>>> On Tue, 21 Jul 2009 14:38:30 -0400, S Viemeister wis temporarily
>>>>> glaikit
>>>>
>>>>>>> Irishmen perhaps?
>>>>>>>
>>>>>>>
>>>>>> We already have loads of Irishmen...
>>>>>
>>>>> Well I, for one, would welcome the return of the wild haggis. This
>>>>> artificial stuff made up by the local butcher just isn't the same...
>>>>
>>>> The last I heard, the Dublin Zoological Gardens had a mating pair. Time
>>>> to restock then..........
>>>
>>> What are young haggises (haggi?) called?
>>
>>I'll have to pass on that one.
>>Perhaps some learned Scot will be along to explain it to us.
>>
>>
> <Austin Powers mode>
>
> Haggibaby!

Didn't Eertha Kitts sing something along that line?
And a big stir it caused, BTW)