In my web application I have a DropDownList that is populated from a DataSet. Once the DropDownList is bound Im attempting to sort it using the following code, but it isnt working, and I cant figure out why
csharp
//first we bind the DropDwnList
DataSet domains = util.BuildDataSet(Server.MapPath("supported_domains.txt"), "Domains", "\t");
supported_domain.DataSource = domains;
supported_domain.DataTextField = domains.Tables[0].Columns[0].ToString();
supported_domain.DataValueField = domains.Tables[0].Columns[0].ToString();
supported_domain.DataBind();
//now we will sort the DropDownList
ListItem[] sorted = new ListItem[supported_domain.Items.Count];
//Response.Write(sorted.Length);
for (int i = 0; i < sorted.Length; i++)
{
sorted[i] = supported_domain.Items[i];
}
Array.Sort(sorted);
supported_domain.Items.Clear();
supported_domain.Items.AddRange(sorted);