Link to home
Start Free TrialLog in
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.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

This seems to do a case independent find:
http://forums.asp.net/p/1238455/2256368.aspx
Avatar of QuinnDex
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

Avatar of 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?
converting to propper case, will turn florida into Florida
lots of ways to do it see below

http://support.microsoft.com/kb/312897
Getting error for both StrConv and VbStrConv.

Is it a function written somewhere. As far as I know it isn't in framework.
its part of the System.Globalization class

add a Imports System.Globalization
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
Avatar of QuinnDex
QuinnDex

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks
>>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 ?