将列数据加载到checkboxlist中

时间:2012-02-05 02:13:37

标签: c# asp.net

我正在尝试将r1,r2,r3列加载到复选框列表中,但输出不是我预期的结果

我的数据库中的数据

问题r1 r2 r3

我是谁? A B C

输出(我的复选框列表中的项目)

A

预期输出

A

C

我试图将r1,r2,r3添加到DataTextField但asp.net不允许我这样做=(

        DataSourceID="SqlDataSource1" DataTextField="r1" DataValueField="r1">

    </asp:CheckBoxList>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 

        SelectCommand="SELECT [r1], [r2], [r3] FROM [ExerciseTable] WHERE ([Question] = @Question)">

        <SelectParameters>

            <asp:Parameter DefaultValue="who am i?" Name="Question" Type="String" />

        </SelectParameters>

1 个答案:

答案 0 :(得分:0)

尝试此选择命令:

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