如何在datalist

时间:2017-02-18 11:05:35

标签: c# asp.net

在下面的数据列表中表示问题和答案的集合,当用户使用C# 点击提交按钮时,如何检查用户是否选择了正确答案单选按钮

<asp:DataList ID="DataList2" runat="server" DataSourceID="AccessDataSource1">
                    <ItemTemplate>
                        Q:
                        <asp:Label ID="QLabel" runat="server" Text='<%# Eval("Q") %>' />
                        <br />
                        <br />
                        A:<asp:RadioButton ID="rb1" runat="server" Text='<%# Eval("A") %>' GroupName="r"  />

                           <br />
                        B:
                        <asp:RadioButton ID="rb2" runat="server" Text='<%# Eval("B") %>' GroupName="r"  />
                                           <br />
                        C:
                        <asp:RadioButton ID="rb3" runat="server" Text='<%# Eval("C") %>' GroupName="r" />

                        <br />
                        D:
                        <asp:RadioButton ID="rb4" runat="server" Text='<%# Eval("D") %>' GroupName="r"  />
                        <br />
                        <br />
                        <asp:Label ID="Label1" runat="server" Text=" Correct Anwser"></asp:Label>
                          </ItemTemplate>
                </asp:DataList>
                <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                    DataFile="~/App_Data/Quize.mdb" 
                    SelectCommand="SELECT [Q], [A], [B], [C], [D] FROM [QuizData]">
                </asp:AccessDataSource>
                <asp:Button ID="Button2" runat="server" Text="Summit" onclick="Button2_Click" />

1 个答案:

答案 0 :(得分:0)

您可以在提交期间简单地参考radioboxes rb1,rb2,rb3 ....:

select * from tbl_billing where str_to_date(date,'%d-%m-%Y')  BETWEEN str_to_date('09-02-2017', '%d-%m-%Y')
            and  str_to_date('10-02-2017', '%d-%m-%Y')

//编辑

但如果你不能尝试找到那些无线电按钮的引用并将它们作为RadioButtons投射

 if (rb1.Checked) {
      ///some code
   }