How to sort a list alphabetically in ASP.NET?

 List<ValueValid> lst = DataService
 .GetProductValidChildren(product.ProdType, (decimal)enumValue);

      

lst gives me a list of country names .. I need to sort this ... can any of you help me?

+2


source to share


4 answers


If the list is not parameterized, you can use:

lst.Sort();

      

EDIT . If it's a list ValueValid

, you can use:



lst.Sort(delegate(ValueValid v1, ValueValid v2) { return v1.Country.CompareTo(v2.Country); });

      

Assuming it ValueValid

has a property named Country

.

+6


source


You can use the Sorting methods in the class List<T>

!



+1


source


You can use System.Collections.SortedList

0


source


lst.OrderBy (w => w.Country));

0


source







All Articles