如何存储和检索学生答案 [英] How to store and retrieve student answer

查看:83
本文介绍了如何存储和检索学生答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用asp.net& amp;开发一个在线考试站点. c#.
我有一个愚蠢的问题,我无法存储和检索学生的答案
表示如果学生选择b作为第一个问题的答案
然后单击下一个按钮,然后单击上一个按钮,将不会选择他的答案.
那是我的问题
我正在使用单选按钮列表显示选择,并将正确的答案以及选定的答案存储在数据库中(SQL Server 2005)
然后我从表中读取数据并将其存储在数据表中
之后,我制定了一种方法来显示数据表中的数据(包括所选答案)并使所选项目等于数据表中的所选答案
但这产生了一个问题,即单选按钮列表的选定索引始终设置为数据库中选定的答案,而不是我更改的答案
尽管我在运行时对该字段(选定答案)进行了更新操作,但仍然无法将选定索引更改为新索引,而只能从db中看到索引


有帮助吗?

Shameel
谢谢您的帮助
我提出了类似您的想法的内容,但此处仍然没有代码(显示方法,下一个按钮和上一个按钮操作)

Hi everyone,

I''m developing an online examination site using asp.net & c#.
I''m having a silly problem, I can''t store and retrieve the student''s answer
meaning that if the student chose b for example as the answer to the first question
then clicked next button then clicked previous button his answer will not be selected .
and that is my problem
I''m using a radio button list to display the choices and I''m storing the correct answer as well as the selected answer in the database(sql server 2005)
then i read the data from the table and stored it in a datatable
after that i made a method to display the data from the datatable(including the selected answer) and made the selected item equal the selected answer in the datatable
but this created the problem which is the selected index of the radio button list is always set to the selected answer from the database not the one i changed
although i made an update operation to this field(selected answer) in runtime still can''t change the selected index to the new one and only sees the index from the db


Any help?

Shameel
Thank u for your help
i made something like your idea but still nothing here is my code(display method,next button and previous button actions)

<pre lang="cs">////////////////////////DISPLAY METHOD///////////////////////////////
public void display()
{
DataRow dr=t.Rows[n];
Label3.Text=dr["q"].ToString();
RadioButtonList1.Items[0].Text = dr["a1"].ToString();
RadioButtonList1.Items[1].Text = dr["a2"].ToString();
RadioButtonList1.Items[2].Text = dr["a3"].ToString();
RadioButtonList1.Items[3].Text = dr["a4"].ToString();
Label4.Text = dr["c_ans"].ToString();
    int index;
if (Session["selected"] != null)
{
    index = RadioButtonList1.Items.IndexOf(RadioButtonList1.Items.FindByText(selected));
}
else
{
     index = RadioButtonList1.Items.IndexOf(RadioButtonList1.Items.FindByText(dr["s_ans"].ToString()));
}
    Response.Write(index);
    RadioButtonList1.Items[index].Selected = true;
}
    ////////////////////////NEXT METHOD///////////////////////////////
    protected void Button2_Click(object sender, EventArgs e)
{
    try
    {
        Button1.Enabled = true;
        Label4.Visible = false;
        n = n + 1;
       // selected = (string)Session["selected"];
        string sql = "update questions set s_ans=''" + selected + "'' where q=''" + Label3.Text + "''";
        Response.Write(sql);
        comm = new SqlCommand(sql, conn);
        int x = comm.ExecuteNonQuery();
        if (n >= t.Rows.Count - 1)
        {
            Button2.Enabled = false;
        }
        Session["selected"] = selected;
        RadioButtonList1.SelectedIndex = -1;
            Session["n"] = n;
            display();
    }
    catch (Exception ex)
    {
        Label4.Visible = true;
        Label4.Text = "Please Choose an answer "+ex.Message;
    }
    }
    ////////////////////////prev METHOD///////////////////////////////
    protected void Button1_Click(object sender, EventArgs e)
    {try
        {
            Button2.Enabled = true;
            Label4.Visible = false;
           // selected = (string)Session["selected"];
                    n = n - 1;
                    if (n == 0)
                    {
                        //n = 0;
                        Button1.Enabled = false;
                    }
                    string sql = "update questions set s_ans=''" + selected + "'' where q=''" + Label3.Text + "''";
                    Response.Write(sql);
                    comm = new SqlCommand(sql, conn);
                    int x = comm.ExecuteNonQuery();
                    Session["selected"] = selected;
                    RadioButtonList1.SelectedIndex = -1;
                    Session["n"] = n;
                    display();
            }
    catch (Exception ex)
    {
        Label4.Visible = true;
        Label4.Text = "Please Choose an answer "+ex.Message;
    }
    }


推荐答案


也许这些项目可以为您提供帮助,并节省一些时间:
这是一个具有asp.net表单和.net 4.0的调查项目构建. http://survey.codeplex.com/ [ ^ ]

或者,如果您对asp.net mvc框架项目感兴趣,那么这也可以帮助您 http://surveymaster.codeplex.com/ [ ^ ]

BR
Hi,
Maybe these projects may help you and save some of your time too:
This is a survey project build with asp.net forms and .net 4.0 http://survey.codeplex.com/[^]

or if you are interested in asp.net mvc framework project this one could help you too http://surveymaster.codeplex.com/[^]

B.R


您必须在用户移至下一个问题后立即将答案存储在Session变量中,并且当用户返回上一个问题时,您要做的就是检查会话以查看问题是否已经回答:如果是,则从会话中恢复答案,如果否,则从数据库中恢复它.
You must store your answer in a Session variable as soon as the user moves to the next question, and when the user goes back to the previous question, all you have to do is to check the Session to see if the question is already answered: if yes, then restore the answer from the session and if no, then restore it from the database.


这篇关于如何存储和检索学生答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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