2

basically i wish to random the item display in dropdownlist ,any function can work with it?

output

a

b

c

expected output (can be any but not only abc)

b

a

c

OR

c

a

b

OR

any


asp:Label ID="Label3" Text=' <%#DataBinder.Eval(Container.DataItem, "Question")%> ' Runat="server"


Select * from (SELECT [r1] AS [Option] FROM [ExerciseTable] WHERE ([Question] = @Question)

UNION SELECT [r2] AS [Option] FROM [ExerciseTable] WHERE ([Question] = @Question) UNION

SELECT [r3] AS [Option] FROM [ExerciseTable] WHERE ([Question] = @Question AND

[r3]!=null))t Order by Newid()"

Chee mun Low
  • 107
  • 10

1 Answers1

0

you can use the Newid() to get the random order

SELECT *
FROM   (SELECT [r1] AS [Option]
        FROM   [ExerciseTable]
        WHERE  ( [Question] = @Question )
        UNION
        SELECT [r2] AS [Option]
        FROM   [ExerciseTable]
        WHERE  ( [Question] = @Question )
        UNION
        SELECT [r3] AS [Option]
        FROM   [ExerciseTable]
        WHERE  ( [Question] = @Question
                 AND [r3] != NULL )) t
ORDER  BY Newid()  

UPDATE

FOR TEST :

CODE:

SELECT *
FROM   (SELECT 'a' AS col
        UNION
        SELECT 'b' AS col
        UNION
        SELECT 'c' AS col) t
ORDER  BY Newid()  

First Time

enter image description here

Second Time

enter image description here

shenhengbin
  • 4,236
  • 1
  • 24
  • 33