Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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)
    {
        // Save off previous answers
        System.Data.DataRowView dr = (System.Data.DataRowView)questionDetails.DataItem;

        // Create Answer object to save values
        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)
        {
            // Go to evaluate answers
            Response.Redirect("Results.aspx");
        }
        else
        {
            questionDetails.PageIndex++;
        }

        if (questionDetails.PageIndex == questionDetails.PageCount - 1)
        {
            nextButton.Text = "Finished";
        }

    }
I tried to fix this problem by putting:
C#
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
Posted
Updated 9-Jan-12 19:46pm
v3

1 solution

Hi,

I guess you are using a single instance of the drop down box for all the data rows.


what are you using for displaying questions,answers,dropdown?

If you are using a grid view for the question and answer, try including the dropdown in the template field of the gridview.This will create multiple instances of dropdown for each datarow.

Hope this helps.
 
Share this answer
 
Comments
matrix388 10-Jan-12 1:29am    
The questions and answers will be displayed inside a DetailsView and the dropdownlist will be underneath the DetailsView. It is not a part of the DetailsView.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900