Thursday, 31 January 2013

How to show the content of a Multiselect List in a sorting order using LINQ


Here is the code below to sort the multiselect list box content in sort order.

Here I am getting the states list and binding it to a multi select List Box.
         public static MultiSelectList GetStatesList(bool selected = false)
        {

            List<string> list = new List<string>();
            if (selected)
                list = RetailManager.GetAllStateList();
            return new MultiSelectList(list.OrderBy(s => s));
        }


The trick lies here i.e s=>s does the task. How it is doing is that internally it is comparing s[i] with s[j].

No comments:

Post a Comment