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
Sumeru suresh
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
João silva
source
to share
You can use the Sorting methods in the class List<T>
!
+1
RichardOD
source
to share
You can use System.Collections.SortedList
0
Ralf de Kleine
source
to share
lst.OrderBy (w => w.Country));
0
JayJay
source
to share