Solved

dropdown list order

Posted on 2008-10-10
12
719 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:Mr_Shaw
  • 8
  • 3
12 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22686934
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
 
LVL 4

Expert Comment

by:ad5qa
ID: 22686937
This is one method of sorting directly from the DDL:

http://www.codeproject.com/KB/aspnet/ASPNET_DropDownList_Sort.aspx
0
 

Author Comment

by:Mr_Shaw
ID: 22686991
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 21

Expert Comment

by:silemone
ID: 22687013
is this ddl dynamic with dynamic data or is the data always the same?
0
 
LVL 21

Expert Comment

by:silemone
ID: 22687045
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
 
LVL 21

Expert Comment

by:silemone
ID: 22687106
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
 

Author Comment

by:Mr_Shaw
ID: 22687115
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
 
LVL 21

Expert Comment

by:silemone
ID: 22687116
oops
sorts after dropdownlist already sorted...   should be sorts after dropdownlist already LOADED
0
 
LVL 21

Accepted Solution

by:
silemone earned 500 total points
ID: 22687130
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
 

Author Closing Comment

by:Mr_Shaw
ID: 31505013
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
 
LVL 21

Expert Comment

by:silemone
ID: 22687150
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
 
LVL 21

Expert Comment

by:silemone
ID: 22687162
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question