Solved

dropdown list order

Posted on 2008-10-10
12
716 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now