//Your (and mine too) one stop shop for all C# .Net and JavaScript code snippets;
Thursday, September 9, 2010
C#: Sort DropDownList
public void SortDropDownList(ref DropDownList ddl)
{
DropDownList ddlClone = new DropDownList();
foreach (ListItem item in ddl.Items)
{
ddlClone.Items.Add(item);
}
var query = ddlClone.Items.Cast
().OrderBy(o => o.Text);
ddl.Items.Clear();
foreach (var item in query)
{
ddl.Items.Add(item);
}
}
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)