jQuery and ASP.NET

January 13, 2009

Easiest way to Convert List to Lower case using LINQ




A user recently asked me a question. He had a List<string> collection that he obtained from a service. He wanted to convert the strings in the List<string> into lower case and then bind it to an ASP.NET DropDownList. He asked me for the simplest way to do so. Here's the solution I suggested him using LINQ:

C#


// Convert to Lower case and bind to dropdownlist

List<string> strList = new List<string> 

{ "One", "TWO", "THree", "Four", "five" };        

strList = strList.ConvertAll(low => low.ToLowerInvariant());

foreach (string s in strList)

{

    DropDownList1.Items.Add(s);

}



VB.NET


        Dim strList As List(Of String) = _

        New List(Of String)(New String() _

                    {"One", "TWO", "THree", "Four", "five"})

        strList = strList.ConvertAll(Function(low)_
        low.ToLowerInvariant())

        For Each s As String In strList

            DropDownList1.Items.Add(s)

        Next s


'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "Easiest way to Convert List to Lower case using LINQ"
  1. Daniel Larsen said...
    April 6, 2010 5:29 PM

    THANK YOU!

 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions