Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dropdown list order

Posted on 2008-10-10
12
Medium Priority
?
725 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 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