.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

dropdown findbyvalue

Posted By: sriram     Posted Date: January 14, 2010    Points:2   Category :.NET Framework

i have to compare dropdown value with the value from dataset field as below. but the problem here is that , dropdown value is say, 'Sriram', and dataset value is 'sriram' . since findbyValue is case sensitive comparision fails.

in this dropdown Datavalue field is unique string value.

And im not supposed to change the dropdown values to either upper or lower case while binding to dropdown.And we dont know initially, the exact value of the dropdown i.e. whether the value is in upper case or lower case.

So, is there any method like FindbyValue to compare by ignoring the case.

And i dont want to use for/foreach loops as there are around 10k records in tht dropdown.

if (ddlOriginator.FindByValue(dsEtaCreation.Tables[0].Rows[0]["FK_Originator"].ToString().Trim())!= null)
// do some code

Author: Faizal             
Posted Date: January 17, 2010     Points: 5   


DropDownList FindByValue method does provide the search using case sensitive. So below is the custom function you can use to find Value from Combo Box in case insensitive

private bool FindByValue(DropDownList ddl, string value)
bool isFound = false;
foreach (ListItem item in ddl.Items)
if (string.Compare(value, item.Value, true) == 0)
isFound = true;

return isFound;

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend