Reputation: 389
I have a dropdownlist which I have populated with the following code:
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"));
}
Now I'm unable to sort the list. Any suggestions on how can I implement it?
Upvotes: 0
Views: 407
Reputation: 14253
You can first create a List
of ListItem
s 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();
Upvotes: 1