?
Solved

dropdown list order

Posted on 2008-10-10
12
Medium Priority
?
723 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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