The web application that I am developing right now has something called quiz engine which provides users with short quizzes which consist of one question or more. Now, I have a problem with taking/ answering the quiz:
When the user tries to participate in a quiz that consists of more than one question and he selects the answer of the first question from the dropdownlist as B, then he goes to the second question, he will see the dropdownlist setting to B not A. I want it to be reset to A but I don't know how to do that.
Any help please?
For creating the Quiz engine, I used the Toturial for the Quiz Engine in the ASP.NET website for creating what I have.
My Code-Behind:
protected void Page_Load(object sender, EventArgs e)
{
questionDetails.DataBind();
answerDropDownList.SelectedIndex = 0;
if (questionDetails.PageCount == 1)
{
nextButton.Text = "Finished";
}
}
protected void nextButton_Click(object sender, EventArgs e)
{
System.Data.DataRowView dr = (System.Data.DataRowView)questionDetails.DataItem;
Answer a = new Answer();
a.QuestionID = dr["QuestionOrder"].ToString();
a.CorrectAnswer = dr["CorrectAnswer"].ToString();
a.UserAnswer = answerDropDownList.SelectedValue.ToString();
ArrayList al = (ArrayList)Session["AnswerList"];
var oldAnswer = al.ToArray().Where(ans => (ans as Answer).QuestionID == a.QuestionID);
if (oldAnswer.Count() != 0)
{
a = oldAnswer.FirstOrDefault() as Answer;
a.CorrectAnswer = dr["CorrectAnswer"].ToString();
a.UserAnswer = answerDropDownList.SelectedValue.ToString();
}
else
{
al.Add(a);
}
if (questionDetails.PageIndex == questionDetails.PageCount - 1)
{
Response.Redirect("Results.aspx");
}
else
{
questionDetails.PageIndex++;
}
if (questionDetails.PageIndex == questionDetails.PageCount - 1)
{
nextButton.Text = "Finished";
}
}
I tried to fix this problem by putting:
answerDropDownList.SelectedIndex = 0;
in the Page_Load, but this doesn't work. Actually, it sets all answers to the first possible answer regardless what the user selects from the DropDownList