Avatar of Johny Bravo
Johny Bravo
 asked on

Find item in dropdownlist

Hi Experts,

I am finding a value in dropdownlist and making it selected.


if (ddlCity.Items.FindByText(Authenticate(Request.QueryString["City"].ToString())) != null)           ddlCity.Items.FindByText(Authenticate(Request.QueryString["City"].ToString())).Selected = true;



When the item present in dropdownlist is "Florida", and I am getting value as "Florida" this works fine, but when I receive "florida" then it won't find the text.

Can I ignore the case sensitivity.
ASP.NET.NET ProgrammingC#

Avatar of undefined
Last Comment
AndyAinscow

8/22/2022 - Mon
AndyAinscow

This seems to do a case independent find:
http://forums.asp.net/p/1238455/2256368.aspx
QuinnDex

try this


if (ddlCity.Items.FindByText(Authenticate(StrConv(Request.QueryString["City"], VbStrConv.ProperCase).ToString())) != null)

ddlCity.Items.FindByText(Authenticate(StrConv(Request.QueryString["City"], VbStrConv.ProperCase).ToString())).Selected = true;

Open in new window

Johny Bravo

ASKER
Thanks for the reply.

AndyAinscow : I don't want to loop through dropdownlist.It will work but looking for better one.

QuinnDex :  What is StrConv and VbStrConv?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
QuinnDex

converting to propper case, will turn florida into Florida
QuinnDex

lots of ways to do it see below

http://support.microsoft.com/kb/312897
Johny Bravo

ASKER
Getting error for both StrConv and VbStrConv.

Is it a function written somewhere. As far as I know it isn't in framework.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
QuinnDex

its part of the System.Globalization class

add a Imports System.Globalization
Johny Bravo

ASKER
Using C#.

using System.Globalization;

if (ddlCity.Items.FindByText(Authenticate(StrConv(Request.QueryString["City"], VbStrConv.ProperCase).ToString())) != null)

Error:

Error      5      The name 'VbStrConv' does not exist in the current context      
Error      4      The name 'StrConv' does not exist in the current context
ASKER CERTIFIED SOLUTION
QuinnDex

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Johny Bravo

ASKER
Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
AndyAinscow

>>AndyAinscow : I don't want to loop through dropdownlist.It will work but looking for better one.

You will probably find that is what is done, just in the background.  (Magic doesn't exist - it is all an illusion).

Just out of interest does the selected comment actually work if the list item is florida instead of Florida ?