Solved

Find item in dropdownlist

Posted on 2013-11-16
11
391 Views
Last Modified: 2013-11-16
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
Comment
Question by:johny_bravo1
  • 5
  • 4
  • 2
11 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
This seems to do a case independent find:
http://forums.asp.net/p/1238455/2256368.aspx
0
 
LVL 9

Expert Comment

by:QuinnDex
Comment Utility
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
 
LVL 8

Author Comment

by:johny_bravo1
Comment Utility
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
 
LVL 9

Expert Comment

by:QuinnDex
Comment Utility
converting to propper case, will turn florida into Florida
0
 
LVL 9

Expert Comment

by:QuinnDex
Comment Utility
lots of ways to do it see below

http://support.microsoft.com/kb/312897
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Author Comment

by:johny_bravo1
Comment Utility
Getting error for both StrConv and VbStrConv.

Is it a function written somewhere. As far as I know it isn't in framework.
0
 
LVL 9

Expert Comment

by:QuinnDex
Comment Utility
its part of the System.Globalization class

add a Imports System.Globalization
0
 
LVL 8

Author Comment

by:johny_bravo1
Comment Utility
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
 
LVL 9

Accepted Solution

by:
QuinnDex earned 500 total points
Comment Utility
different aproach for c# sorry



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

Open in new window

0
 
LVL 8

Author Closing Comment

by:johny_bravo1
Comment Utility
Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now