Wardeaux
2/6/2004 4:15:00 PM
Robert,
there may be a "slicker" way to get this done, but I've found I have to
convert BOTH strings to either Upper or Lower case in order to get a case
insensative compare. Options:
1) Convert your DropDownList text to upper case and then
MySel.SelectedIndex =
MySel.Items.IndexOf(MySel.Items.FindByText(strToFind.ToUpper()))
2) If you desire the mixed case DropDownList text (looks MUCH nicer) then
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()))
The only other option I see is to do like Jeffery suggested and run the list
item-by-item. This may be necessary if the Value is an ID from a
"Countries" table and you still want mixed case in your DropDownList...
Hope this helps!
wardeaux
"Robert Strickland" <strickra@rjsonline.net> wrote in message
news:%23FPFKaL7DHA.2460@TK2MSFTNGP09.phx.gbl...
> Thanks for the code. This will work but I have a question concerning the
> FindByText method from the asp:dropdownlist web control. It appears the
> search is case sensitive. Is there anyway around this?
>
> Bob
>
> ""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
> news:snmYTKF7DHA.1992@cpmsftngxa07.phx.gbl...
> >
> > Hi Robert,
> >
> > Thank you for posting in the community!
> >
> > Based on my understanding, you meet the text matching problem in
> > DropDownList.
> > That is: The Country text in your dropdownlist is "France", while the
> > maching text from the customer may be "France" or "FRANCE". Then the
> > "France" matches well, but "FRANCE" does not match.
> >
> > ======================================================
> > I think the behavior depends on your text matching implementation. How
do
> > you implement your program logic?
> >
> > I suppose you loop through all the items in the DropDownList and use
> > ListItem.Text property to match.
> >
> > So I wrote a sample project like this:
> >
> > 1). The items in the DropDownList are:
> > USA
> > France
> > England
> > Canada
> >
> > 2). Match code:
> > private void Button1_Click(object sender, System.EventArgs e)
> > {
> > string matchingstr="France";
> > for(int i=0; i<DropDownList1.Items.Count;i++)
> > {
> > if(DropDownList1.Items[i].Text.Equals(matchingstr))
> > {
> > DropDownList1.SelectedIndex=i;
> > }
> > }
> > }
> >
> > But using matchingstr="FRANCE" will fail.
> >
> > So I think you can use String class to make them the same lower-case or
> > upper-case:
> > private void Button1_Click(object sender, System.EventArgs e)
> > {
> > string matchingstr="FRANCE";
> > for(int i=0; i<DropDownList1.Items.Count;i++)
> > {
> > if(DropDownList1.Items[i].Text.ToLower().Equals(matchingstr.ToLower()))
> > {
> > DropDownList1.SelectedIndex=i;
> > }
> > }
> > }
> >
> > This will work.
> > If I misunderstand you, please feel free to tell me.
> >
> > ==========================================================
> > Please apply my suggestion above and let me know if it helps resolve
your
> > problem.
> >
> > Thank you for your patience and cooperation. If you have any questions
or
> > concerns, please feel free to post it in the group. I am standing by to
be
> > of assistance.
> > Have a nice day!!
> >
> > Best regards,
> > Jeffrey Tan
> > Microsoft Online Partner Support
> > Get Secure! - www.microsoft.com/security
> > This posting is provided "as is" with no warranties and confers no
rights.
> >
>
>