Sorting a DropDownList? - C#, ASP.NET

前端 未结 23 1059
慢半拍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 19:45

    var list = ddl.Items.Cast().OrderBy(x => x.Text).ToList();
    
    ddl.DataSource = list;
    ddl.DataTextField = "Text";
    ddl.DataValueField = "Value"; 
    ddl.DataBind();
    

提交回复
热议问题