Solved

ASP.NET MVC dropdown list - OrderBy

Posted on 2016-07-20
2
46 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
Comment Utility
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
Comment Utility
The link was very useful; I managed to fix the problem.
Thank you very much!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP Sum Column in Table 3 26
PHP loop not working 4 29
ASP.NET reading ATOM 2 22
writting html or javascript in PHP 8 8
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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