Sorting the dropdown list
I have a dropdownlist dynamically filled开发者_如何学Go from file folder and the dropdown filled with the name of the files in the folder like
JUN-2010,APR-2010,MAY-2010,SEP-2010,FEB-2011,DEC-2010
How can I sort this dropdownlist ?
Try this following code. where foldernames is list of strings.
var s = from dt in foldernames
orderby DateTime.ParseExact(dt, "MMM-yyyy", culture) ascending
select( dt);
Bind var s in the dropdownlist.
You can add those dates to List<DateTime>
list and then use folowing:
list.Sort(delegate(DateTime x, DateTime y){ return y.CompareTo(x); });
then just attach to your dropdown.
精彩评论