Click here to Skip to main content
13,259,847 members (46,400 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 21 Aug 2007

Sorting Dropdown list in ASP.NET using C#

, 21 Aug 2007
Rate this:
Please Sign up or sign in to vote.
There is a simple solution for sorting Dropdown list in ASP.NET


I found a big problem in ASP.NET is there was no direct method for sorting the items in the Dropdown list. Sometimes this sorting functionality is required in the applications.

Here I gave a small and easy technique of sorting the Dropdown list in ASP.NET

Using the code

I assumed that, you have a Dropdown list in your ASPX page with name "DropDownList1". I have added few items to this Dropdown list in the Page_Load event with disorder manner.

protected void Page_Load(object sender, EventArgs e)

SortDDL(ref this.DropDownList1);

In the Page_Load event, I have called a function "SortDDL" for sorting the Dropdown list. In this function we have to pass the reference of the required Dropdown list. Then system will automatically sort the items in the given Dropdown list.

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

    foreach (ListItem li in objDDL.Items)


    foreach (object item in textList)
        string value = objDDL.Items.FindByText(item.ToString()).Value;

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

We should need to import the following namespace for getting ArrayList class.

<p style="TEXT-INDENT: 0.5in">using System.Collections; 


Happy Coding to All!!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

RB Changanacherry
Team Leader
India India
I am Rajesh Babu, currently working for Nous Infosystems, Bangalore. I have 6 plus years experience in Microsoft Technologies.

You may also be interested in...


Comments and Discussions

QuestionConverting to VB Pin
Timothy Vandeweerd13-Nov-14 10:11
memberTimothy Vandeweerd13-Nov-14 10:11 
GeneralSortableDropDownList Pin
sross9011-May-09 0:37
membersross9011-May-09 0:37 
GeneralGood article! Pin
indpride128-Aug-07 21:01
memberindpride128-Aug-07 21:01 
GeneralRe: Good article! Pin
Member 448198722-May-08 1:34
memberMember 448198722-May-08 1:34 
GeneralVery Good Article Pin
prr77715-Apr-10 1:05
memberprr77715-Apr-10 1:05 
GeneralHi, 3 loops ..... Pin
kaken2022-Aug-07 1:59
memberkaken2022-Aug-07 1:59 
GeneralRe: Hi, 3 loops ..... Pin
tkrafael_net22-Aug-07 3:16
membertkrafael_net22-Aug-07 3:16 
GeneralRe: Hi, 3 loops ..... Pin
Jay Thakar5-Feb-10 6:32
memberJay Thakar5-Feb-10 6:32 
GeneralC# example Pin
Adam Marzi4-Feb-09 13:32
memberAdam Marzi4-Feb-09 13:32 
GeneralRe: C# example Pin
senthilpsp11-Feb-09 1:16
membersenthilpsp11-Feb-09 1:16 
GeneralRe: C# example Pin
UdeS23-Mar-09 3:45
memberUdeS23-Mar-09 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 22 Aug 2007
Article Copyright 2007 by RB Changanacherry
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid