0

我有一个下拉列表,其中填充了以下代码:

statusList.Items.Add(new ListItem(Inactive_AddUser, "0"));
statusList.Items.Insert(0, new ListItem(Select, Select));
if (activeUser < (Convert.ToInt32(Session["MaxActiveUsers"])))
 {
   statusList.Items.Add(new ListItem(Active_AddUser, "1"));
 }

现在我无法对列表进行排序。关于如何实施它的任何建议?

4

1 回答 1

1

You can first create a List of ListItems then sort it and after all bind it to DropDownList some thing like this that I found from here:

List<ListItem> items;//fill this with your own items
items.Sort((x, y) => x.Text.CompareTo(y.Text));
statusList.DataSource = items;
statusList.DataBind();
于 2013-06-11T15:17:04.243 回答