dropdown list order

I have a dropdown list which I really want to change the order fo the item.

At the moment it is showing 2007-08, 2008-09. How to I change the default to show 2008-09, 2007-08
Mr_ShawAsked:
Who is Participating?
 
silemoneCommented:
yes...just add them in the order you want...by that wizard...whatever order you add them in is the order they will show...the way you are adding them is the index that they will have...
0
 
silemoneCommented:
just change the index...i.e. make 0 = 1 and 1 = 2...but even better, just make the datasource return data in sorted order...i.e...order by  DateField desc/asc

0
 
ad5qaCommented:
This is one method of sorting directly from the DDL:

http://www.codeproject.com/KB/aspnet/ASPNET_DropDownList_Sort.aspx
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Mr_ShawAuthor Commented:
I am adding the data directly to the Dropdown so list there is no SQL for me to do Asc or Desc.

How do I change the index. nothing is coming up in intellisense.
0
 
silemoneCommented:
is this ddl dynamic with dynamic data or is the data always the same?
0
 
silemoneCommented:
what do you mean adding the data directly from the dropdown?  you're not binding it?  you're doing it by code

like foreach(....?
0
 
silemoneCommented:
anyway, adSga way should work also, but the only thing is that i don't like about it is that is sorts after dropdownlist already sorted...if you're talking about pulling directly from a table, then you should be able to get the data from Table presorted...


//Below myDataTable is a DataTable...so we make a DataRow ...

DataRow[] filterRows = myDataTable.Select("Unit_Price < 40", "unit_price desc");

then pull from here rather than from regular rows...

i.e.

Foreach (DataRow x in filterRows)
{
       //add to DDL...
}
 

Above C# code shows the use of sort parameter with string value to filter the rows of DataTable based on search filterExpression. You can match the output here:
0
 
Mr_ShawAuthor Commented:
I am using Visual studio.
on the design screen i click the dropdown list and select edit items.

on the new screen i add an item
0
 
silemoneCommented:
oops
sorts after dropdownlist already sorted...   should be sorts after dropdownlist already LOADED
0
 
Mr_ShawAuthor Commented:
Thanks,
It turned out what I had to do was delete all the current items then click ok (at this point now items were in the listbox). Then go back and add the items to the list box. Good thing I only had two items.
0
 
silemoneCommented:
or add them directly in the aspx page...

like this:

<asp:DropDownList ID="DropDownList1" runat="server">
          <asp:ListItem Value="0" Text="zero">
          <asp:ListItem Value="1" Text= "one">
        </asp:DropDownList>

and they will appear in the order they have been added...
0
 
silemoneCommented:
well its just as easy if you have more items...because SQL or DataTable can presort for you...but good job and good luck...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.