protected void Page_Load(object sender, EventArgs e) { ArrayList al = (ArrayList)Session["AnsList"]; gvResults.DataSource = al; gvResults.DataBind(); if(IsPostBack == false) { int questions = al.Count; int correct = 0; for(int i = 0; i < al.Count; i++) { answer = (Answer)al[i]; if (answer.Result == Answer.ResultValue.Correct) { correct = correct+1; } } lblResult.Text = "Your score is " + correct + " out of 10"; if (correct < 3) { lblResultExp.Text = "You score is low. You should go to a specialist and be re-examined"; } else if (correct > 3 && correct < 7) { lblResultExp.Text = "There is a possibilty you are colourbind. You may want to be re-examined by a specialist"; } else lblResultExp.Text = "You appear to have Normal Colour Vision"; } }
protected void btnNext_Click(object sender, EventArgs e) { try { Answer ans = new Answer(); if (txtAnswer.Text == "") { lblMessage.Text = "**You must answer this question before moving onto the next question**"; } else { //Save previous answers System.Data.DataRowView dr = (System.Data.DataRowView)FV_QuesDetails.DataItem; //new instance of Answer class object to store values ans.quesID = dr["Ques_Ord"].ToString(); ans.correctAns = dr["Ans_Norm"].ToString(); ans.userAns = txtAnswer.Text; ans.checkResult(); //Retrieve answer list ArrayList al = (ArrayList)Session["AnsList"]; //Add new answer to answer list al.Add(ans); //Save answer back to memory Session.Add("AnsList", al); //next question if (FV_QuesDetails.PageIndex == FV_QuesDetails.PageCount - 1) { btnNext.Text = "Finished"; Response.Redirect("Results.aspx"); } else { //increment page indexing on each form view FV_QuesDetails.PageIndex++; ImageFV.PageIndex++; //display next question number from the question order column in the question label lblQues.Text = " Question: " + dr["Ques_Ord"].ToString(); //empty the text box txtAnswer.Text = ""; } } } catch (Exception ex) { throw ex; } }