<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BusinessQuestions.aspx.cs" Inherits="BusinessQuestions" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div style="height: 640px"> <br /> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick"> </asp:Timer> <br /> <br /> <br /> <br /> <br /> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> <ContentTemplate> <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="Medium" Text="Label"></asp:Label> <br /> <br /> <br /> <br /> <asp:RadioButtonList ID="RadioButtonList1" runat="server" BackColor="#003399" BorderColor="#0000CC" BorderStyle="Solid" ForeColor="White"> </asp:RadioButtonList> <br /> <br /> </ContentTemplate> </asp:UpdatePanel> <br /> <br /> <br /> <br /> <br /> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Next" /> </div> </form> </body> </html>
public partial class BusinessQuestions : System.Web.UI.Page { int intTotalQuestion; int intQuestionNo = 1; int intScore = 0; ArrayList Answers; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { intTotalQuestion = 15; ViewState["StartTime"] = DateTime.Now; //ShowQuestion(intQuestionNo); Timer1_Tick(sender, e); } } protected void Timer1_Tick(object sender, EventArgs e) { ShowQuestion(intQuestionNo); } public void ShowQuestion(int intQuestionNo) { string XmlPath = Server.MapPath("Business-Questions.xml"); XPathDocument xdoc = new XPathDocument(XmlPath); XPathNavigator xNav = xdoc.CreateNavigator(); XPathNodeIterator xNodeIterator; string strXpath; int intLoop; strXpath = "/quiz/mchoice[" + intQuestionNo.ToString() + "]"; xNodeIterator = xNav.Select(strXpath + "/question"); while(xNodeIterator.MoveNext()) { Label1.Text = intQuestionNo.ToString() + ". " + xNodeIterator.Current.Value; xNodeIterator = xNav.Select(strXpath + "/answer"); RadioButtonList1.Items.Clear(); intLoop = 0; while (xNodeIterator.MoveNext()) { intLoop += 1; //intScore = 0; RadioButtonList1.Items.Add(new ListItem(xNodeIterator.Current.Value, intLoop.ToString())); if (xNodeIterator.Current.GetAttribute("correct", "") == "yes") { ViewState["CorrectAnswer"] = intLoop; } } } ViewState["TotalQuestion"] = intTotalQuestion; ViewState["QuestionNo"] = intQuestionNo; ViewState["Score"] = intScore; ViewState["AnswerHistory"] = Answers; } protected void Button1_Click(object sender, EventArgs e) { intTotalQuestion = (int)ViewState["TotalQuestion"]; intQuestionNo = (int)ViewState["QuestionNo"]; intScore = (int)ViewState["Score"]; Answers = (ArrayList)ViewState["AnswerHistory"]; if (RadioButtonList1.SelectedItem == null) { intScore += 0; } else if (RadioButtonList1.SelectedItem.Value == ViewState["CorrectAnswer"].ToString()) { intScore += 10; } else { intScore = intScore - 1; } if (intQuestionNo == intTotalQuestion) { Response.Write("Your Score is " + intScore.ToString() + " Points"); Response.Write("\n\n"); Response.Write("Quiz over"); } else { intQuestionNo = intQuestionNo + 1; ShowQuestion(intQuestionNo); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)