• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

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.
0
Johny Bravo
Asked:
Johny Bravo
  • 5
  • 4
  • 2
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
This seems to do a case independent find:
http://forums.asp.net/p/1238455/2256368.aspx
0
 
QuinnDexCommented:
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

0
 
Johny BravoAuthor Commented:
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?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
QuinnDexCommented:
converting to propper case, will turn florida into Florida
0
 
QuinnDexCommented:
lots of ways to do it see below

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

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

add a Imports System.Globalization
0
 
Johny BravoAuthor Commented:
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
0
 
QuinnDexCommented:
different aproach for c# sorry



if (ddlCity.Items.FindByText(Authenticate(CultureInfo.CurrentCulture.TextInfo.ToTitleCase((Request.QueryString["City"]).ToString())) != null)

Open in new window

0
 
Johny BravoAuthor Commented:
Thanks
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>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 ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now