Solved

ASP.NET MVC dropdown list - OrderBy

Posted on 2016-07-20
2
56 Views
Last Modified: 2016-07-20
Hi Experts,
This code shows a dropdown list on my webpage, but it orders it by ID, not by Code, as I would like it to do it.

@Html.DropDownList("DelayCodesDDL", null, new { style = "background-color:#ffecb0; width:60px;" })

How could I make it order it by Code ascending? The table from where the dropdown list is populated hast two columns: ID, and Code.

Thank you for your help.
0
Comment
Question by:romsom
2 Comments
 
LVL 18

Accepted Solution

by:
Anil Golamari earned 500 total points
ID: 41721434
If you want to sort the dropdown list by value and not by the key of the element then you can use linq to first sort the data source and then you can assign it to dropdown.

Check this link
1
 

Author Closing Comment

by:romsom
ID: 41721960
The link was very useful; I managed to fix the problem.
Thank you very much!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

813 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

9 Experts available now in Live!

Get 1:1 Help Now