在线考试系统 [英] online examination system
本文介绍了在线考试系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生
下一个问题按钮的代码有问题.我编写了代码,但是单击下一步按钮时,它仅显示两个问题.
我的代码如下:-
sir
have a problem in code for the next question button. i write a code but on clicking the next button it shows only two questions.
my code is as follows:-
public partial class test : System.Web.UI.Page
{
int x = 0;
int ans1 = 0;
SqlConnection ob = new SqlConnection(ConfigurationManager.ConnectionStrings["upsc"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
question();
}
protected void question()
{
ob.Open();
String a = "Select que,op1,op2,op3,op4,answer from test";
SqlDataAdapter objcmd = new SqlDataAdapter(a, ob);
DataSet ds = new DataSet();
objcmd.Fill(ds, "exam" );
lblQues.Text = ds.Tables["exam"].Rows[x][0].ToString();
RadioButton1.Text = ds.Tables["exam"].Rows[x][1].ToString();
RadioButton2.Text = ds.Tables["exam"].Rows[x][2].ToString();
RadioButton3.Text = ds.Tables["exam"].Rows[x][3].ToString();
RadioButton4.Text = ds.Tables["exam"].Rows[x][4].ToString();
ans.Text = ds.Tables["exam"].Rows[x][5].ToString();
x++;
ob.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
ob.Open();
lblQues.Text = ds.Tables["exam"].Rows[x][0].ToString();
RadioButton1.Text = ds.Tables["exam"].Rows[x][1].ToString();
RadioButton2.Text = ds.Tables["exam"].Rows[x][2].ToString();
RadioButton3.Text = ds.Tables["exam"].Rows[x][3].ToString();
RadioButton4.Text = ds.Tables["exam"].Rows[x][4].ToString();
ans.Text = ds.Tables["exam"].Rows[x][5].ToString();
x++;
}
}
推荐答案
如代码所示,
在Page_Load
上,它将第一个问题加载为x = 0,在Button1_Click
上,它在x变为1时显示第二个问题.根据提供的代码,您正在编写并说过此代码.
我假设通过说它仅显示两个问题" ,您可能希望根据按钮的单击顺序显示问题.如果是这样,您可以尝试,
- 您可以根据当前问题的编号分别检索每个问题,而无需将其存储在某处,请阅读有关 ASP.NET状态管理概述 [ ^ ].一次检索一个问题可能存在性能问题.
As the code shows,
On thePage_Load
it loads the first question as x=0 and on theButton1_Click
it shows the second question as x becomes 1. Based on the provided code it is doing as you wrote and said.
I assume by saying "it shows only two questions" you might want to display the question in sequence based on the button click. If that''s the case, you might try,
- You might retrieved each question individually based on the current question no which you need to store somewhere, read more about ASP.NET State Management Overview[^]. There might be performance issue for retrieving one question at a time.
这篇关于在线考试系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文