随机获取显示数据到下拉列表

时间:2012-02-07 00:43:53

标签: c# asp.net

基本上我希望在dropdownlist中随机显示项目,任何函数都可以使用吗?

输出

B'/ P>

C

预期输出(可以是任何但不仅仅是abc)

B'/ P>

C

OR

C

B'/ P>

OR

任何


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


选择* 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由Newid()命令“

1 个答案:

答案 0 :(得分:0)

您可以使用Newid()获取随机顺序

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()  

<强>更新

FOR TEST:

代码:

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

第一次

enter image description here

第二次

enter image description here