//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);
You're Browsing As A Guest! Register Now... |
||
|
Become a ASP.NET Expert!
Join 416,721 ASP.NET Programmers for FREE! Get instant access to thousands
of ASP.NET experts, tutorials, code snippets, and more! There are 2,869 people online right now.Registration is fast and FREE... Join Now!
|
||
Page 1 of 1
Sorting a DropDownList
#1
Sorting a DropDownList
Posted 28 February 2008 - 11:12 PM
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
#2
Re: Sorting a DropDownList
Posted 28 February 2008 - 11:27 PM
It's probably something to do with the data binding, so you can't your own entries to it.
Have you tried setting the Sorted property to true? (assuming the DropDownList supports it).
Have you tried setting the Sorted property to true? (assuming the DropDownList supports it).
This post has been edited by Nayana: 28 February 2008 - 11:28 PM
#3
Re: Sorting a DropDownList
Posted 28 February 2008 - 11:37 PM
A DropDownList doesn't support sorting. Guess I can try to sort the items before adding them to the DataSet, but that just seems like a ton of work.
Well the code works on a non data bound DropDownList, so back to the drawing board lol
Well the code works on a non data bound DropDownList, so back to the drawing board lol
Page 1 of 1


Ask A New Question
Reply




MultiQuote






|