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 javascript ?
the answer is stored in database.
Datalist:
<asp:DataList ID="DataList1" runat="server" DataKeyField="Qno"
DataSourceID="SqlDataSource1">
<ItemTemplate>
Qno:
<asp:Label ID="QnoLabel" runat="server" Text='<%# Eval("Qno") %>' />
<br />
Question:
<asp:Label ID="QuestionLabel" runat="server" Text='<%# Eval("Question") %>' />
<br />
<asp:RadioButton ID="RadioButton1" runat="server" Text='<%# Eval("Ans1") %>' />
<br />
<asp:RadioButton ID="RadioButton2" runat="server" Text='<%# Eval("Ans2") %>' />
<br />
<asp:RadioButton ID="RadioButton3" runat="server" Text='<%# Eval("Ans3") %>' />
<br />
<asp:RadioButton ID="RadioButton4" runat="server" Text='<%# Eval("Ans4") %>' />
<br />
<asp:Button ID="Button2" runat="server" Text="Submit" />
<br />
</ItemTemplate>
</asp:DataList>
Provide a CommandName parameter for the Button2 in the DataList: CommandName=”Validate”
Add the OnItemCommand event for the DataList1: *OnItemCommand=”DataList1_OnItemCommand”*
In the code behind, fill-in the *DataList1_OnItemCommand* event actions:
Take required actions based on which check box is checked.