In below data list represents set of question's and answer, How to check whether the user selected right answer radio button or not when the user clicks on submit button using 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" />
You can simply reference to radioboxes rb1,rb2,rb3.... during submit i.e:
if (rb1.Checked) {
///some code
}
// EDIT
but if you cant, try to find reference to those radiobuttons and cast them as RadioButtons
RadioButton rb1 = (RadioButton)dataItem.FindControl("rb1");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments