Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select dropdown list item findbytext without case sensitivity vb.net

Tags:

asp.net

vb.net

I want to select one item in drop down list in ASP.NET written with VB.NET - I have values and texts in listbox like this:

Volvo
Audi
etc...

But values coming from other place in upper case... VOLVO, AUDI..

This code:

dropdownlist.FindByValue("CAPITAL")

Is not working and giving null for Volvo.. please help.

like image 349
k-s Avatar asked Feb 08 '12 14:02

k-s


2 Answers

One way would be LINQ:

Dim volvoItem = dropdownlist.Items.Cast(Of ListItem)().
    FirstOrDefault(Function(i) i.Text.Equals("Volvo", StringComparison.InvariantCultureIgnoreCase))

C#:

var volvoItem = dropdownlist.Items.Cast<ListItem>()
   .FirstOrDefault(i => i.Text.Equals("Volvo", StringComparison.InvariantCultureIgnoreCase));
like image 55
Tim Schmelter Avatar answered Oct 03 '22 23:10

Tim Schmelter


This worked for me

foreach(ListItem li in dropdownlist.Items)
    {
        if (String.Compare(li.Text, myLabel.Text, true) == 0)
            myCustomValidator.IsValid = false;  // Match Found !
    }
like image 33
rohithrrao Avatar answered Oct 04 '22 01:10

rohithrrao