Solved

Find item in dropdownlist

Posted on 2013-11-16
11
392 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
ID: 39653007
This seems to do a case independent find:
http://forums.asp.net/p/1238455/2256368.aspx
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39653074
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
ID: 39653100
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
ID: 39653104
converting to propper case, will turn florida into Florida
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39653107
lots of ways to do it see below

http://support.microsoft.com/kb/312897
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 8

Author Comment

by:johny_bravo1
ID: 39653108
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
ID: 39653110
its part of the System.Globalization class

add a Imports System.Globalization
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 39653122
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
ID: 39653126
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
ID: 39653128
Thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39653203
>>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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

20 Experts available now in Live!

Get 1:1 Help Now