如何使用下面的代码获取上一个问题.. [英] how to get previous question by using below code..

查看:67
本文介绍了如何使用下面的代码获取上一个问题..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,当我点击上一个按钮时,我想得到上一个问题,我得到了下一个问题,但我不能为之前的问题做,所以请写一个鳕鱼或给我一个推荐网址....我希望你理解我的问题...谢谢。我在等你的回复





friends i want to get previous question when i am click on previous button , i got a next question but i can not do for previous question so please write a cod or give a refer url to me.... i hope you understand my problem...Thank you.i am waiting for your reply


protected void btn_next_Click(object sender, EventArgs e)
{

getNextQuestion();
}
protected void btn_startexam_Click(object sender, EventArgs e)
{

btn_startexam.Visible = false;
Panel1.Visible = true;
int score = Convert.ToInt32(txtScore.Text);
lblScore.Text = "Score : " + Convert.ToString(score);
Session["counter"] = "1";
Random rnd = new Random();
int i = rnd.Next(1, 10);//Here specify your starting slno of question table and ending no.

getQuestion(i);

}
public void getQuestion(int no)
{
string str = "select * from Question where slNo=" + no + "";
SqlDataAdapter da2 = new SqlDataAdapter(str, sqlconn);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "Question");
if (ds2.Tables[0].Rows.Count > 0)
{
DataRow dtr;
int i = 0;
while (i < ds2.Tables[0].Rows.Count)
{
dtr = ds2.Tables[0].Rows[i];
Session["Answer"] = Convert.ToString(Convert.ToInt32(dtr["Correct"].ToString()) - 1);
lblQuestion.Text = "Q." + Session["counter"].ToString() + " " + dtr["Question"].ToString();
RblOption.ClearSelection();
RblOption.Items.Clear();
RblOption.Items.Add(dtr["Option1"].ToString());
RblOption.Items.Add(dtr["Option2"].ToString());
RblOption.Items.Add(dtr["Option3"].ToString());
RblOption.Items.Add(dtr["Option4"].ToString());
i++;
}
}
}

 

public void getNextQuestion()
{
if (Convert.ToInt32(Session["counter"].ToString()) < 10)//10 is a counter which is used for 10 questions
{
if (RblOption.SelectedIndex >= 0)
{
if (Session["Answer"].ToString() == RblOption.SelectedIndex.ToString())
{
int score = Convert.ToInt32(txtScore.Text) + 1;// 1 for mark for each question
txtScore.Text = score.ToString();
lblScore.Text = "Score : " + Convert.ToString(score);
}
}

Random rnd = new Random();
int i = rnd.Next(1, 10);
//lblQuestion.Text = i.ToString();
getQuestion(i);
Session["counter"] = Convert.ToString(Convert.ToInt32(Session["counter"].ToString()) + 1);

}
else
{
Panel2.Visible = false;
//code for displaying after completting the exam, if you want to show the result then you can code here.
}
}
 
 
 
 
public void GetPrevQuestion(int prev)
{
//write your code for me...
} 

推荐答案

如果您想允许用户前后移动,那么您不应该实时使用随机选择。

相反,当您开始测试时,选择十个不同的问题并将它们作为数组存储在会话中。设置第二个带有得分的数组,并将它们预设为未答复。

然后当你向前转,你可以访问存储的问题数组以获得下一个问题,同样可以访问以前。如果你不这样做,那么你的候选人可以继续前进,直到他得到问题,他确实知道...的答案:笑:
If you want to allow the user to go back and forward, then you shouldn't use random selection "on the fly" as it were.
Instead, when you start the test select ten different questions and store them in the Session as an array. Set up a second array with the "scores" and preset them to "unanswered".
Then when you more forward, you access the stored array of questions to get the next question and the same to access the previous. If you don't, then your candidate can just keep going back and forwards until he gets questions he does know the answer to... :laugh:


这篇关于如何使用下面的代码获取上一个问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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