Sorting a DropDownList? - C#, ASP.NET

前端 未结 23 1120
慢半拍i
慢半拍i 2020-12-08 19:17

I\'m curious as to the best route (more looking towards simplicity, not speed or efficiency) to sort a DropDownList in C#/ASP.NET - I\'ve looked at a few recommendations b

23条回答
  •  佛祖请我去吃肉
    2020-12-08 20:09

    Assuming you are running the latest version of the .Net Framework this will work:

    List items = GetItemsFromSomewhere();
    items.Sort((x, y) => string.Compare(x, y));
    DropDownListId.DataSource = items;
    DropDownListId.DataBind();
    

提交回复
热议问题