.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Sorting Dropdownlist in ASP.NET:

Posted By:Athira Sreejith       Posted Date: December 31, 2008    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

Sorting Dropdownlist in ASP.NET: Below is the code sample used to sort the DropDownList. This function will take DropDownList and an input asd it will sort the value Inside Dropdownlist.

private void fnSortDDL(ref DropDownList objDDL)
{
ArrayList textList = new ArrayList();
ArrayList valueList = new ArrayList();

foreach (ListItem li in objDDL.Items)
{
textList.Add(li.Text);
}

textList.Sort();
foreach (object item in textList)
{
string value = objDDL.Items.FindByText(item.ToString()).Value;
valueList.Add(value);
}
objDDL.Items.Clear();

for (int i = 0; i < textList.Count; i++)
{
ListItem objItem = new ListItem(textList[i].ToString(), valueList[i].ToString());
objDDL.Items.Add(objItem);
}
}

Call:
fnSortDDL(dropdownlist1);
 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend