Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 400
  • 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_bravo1
Asked:
johny_bravo1
  • 5
  • 4
  • 2
1 Solution
 
AndyAinscowCommented:
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_bravo1Author 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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_bravo1Author 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_bravo1Author 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_bravo1Author Commented:
Thanks
0
 
AndyAinscowCommented:
>>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

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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