如何在此测验系统中重置DropDownList? [英] How to reset the DropDownList in this Quiz system?

查看:92
本文介绍了如何在此测验系统中重置DropDownList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在开发的Web应用程序有一个称为测验引擎的东西,它为用户提供由一个或多个问题组成的简短测验.现在,我在参加/回答测验时遇到问题:

当用户尝试参加由多个问题组成的测验,并且他从下拉列表中选择第一个问题的答案为B时​​,他将转到第二个问题,他将看到下拉列表设置为B而不是A.我希望将其重置为A,但是我不知道该怎么做.

有什么帮助吗?


为了创建测验引擎,我在ASP.NET网站中使用了Toturial for Quiz Engine创建了我拥有的东西.

我的后台代码:

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)
    {
        // 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:

answerDropDownList.SelectedIndex = 0;


在Page_Load中,但这不起作用.实际上,无论用户从DropDownList中选择什么,它都会将所有答案设置为第一个可能的答案.


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

推荐答案



我猜您正在对所有数据行使用下拉框的单个实例.


您使用什么来显示问题,答案,下拉菜单?

如果您将网格视图用于问答,请尝试将下拉列表包括在gridview的模板字段中,这将为每个数据行创建多个下拉列表实例.

希望这会有所帮助.
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.


这篇关于如何在此测验系统中重置DropDownList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆