0

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?

Esha
  • 391
  • 1
  • 9
  • 37

1 Answers1

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();
Community
  • 1
  • 1
Majid
  • 13,853
  • 15
  • 77
  • 113