Click here to Skip to main content
15,034,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to display shuffled items in a dropdownlist. I am binding dynamic items from database to dropdonlist..Whenever I opens that page I need values should appear shuffled or randomly..

Hi, if you use MSSQL, here is your solution:

SELECT column1, column2, column3
FROM your_table
Mansi Arora 8-Aug-11 5:14am
I am using SQLSERVER 2008
Van Hua 8-Aug-11 5:42am
So, let try my suggest query :)
Shuffle DataRow in DataTable[^]

In DB you can use RAND()
Van Hua 8-Aug-11 3:42am
RAND() is use for MySQL
thatraja 8-Aug-11 3:47am
Agree, But he didn't mention any database in his question ;-)
If you are binding directly to a DataTable or other source that comes from a database, then the display order (assuming that you have not set the Sorted property true) will always be that returned form the database. Your only option here is to re-order the items into a new structure (such as a List<T> or and Array) befiore you bind the data.

Why do you want to randomize user data though - you will probably seriously annoy your users. Personally, if a list is not alphabetical, then I expect it to be in a task-centric order, with most common items at the top. If these moved randomly, I would be quite peeved with you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900