dropDownList排序

private void dropDownListSort(DropDownList ddl)
        {
            ListItem listItem = new ListItem();
            for (int i = 0; i < ddl.Items.Count; i++)
            {
                for (int j = i + 1; j < ddl.Items.Count; j++)
                {
                    if (ddl.Items[i].Text.CompareTo(ddl.Items[j].Text) > 0)
                    {
                        listItem = ddl.Items[j];
                        ddl.Items.Remove(ddl.Items[j]);
                        ddl.Items.Insert(i, listItem);

                        listItem = ddl.Items[i + 1];
                        ddl.Items.Remove(ddl.Items[i + 1]);
                        ddl.Items.Insert(j, listItem);
                    }
                }
            }
            ddl.SelectedIndex = -1;
        }

你可能感兴趣的:(dropDownList排序)