开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜