Click here to Skip to main content
15,909,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
the code i have so far tried

protected void Page_Load(object sender, EventArgs e)
 { 
if (!IsPostBack) 
{ 
Time(); 
Question(); 
}

}
public void Question()
{
int res2 = Convert.ToInt32(lblsubject.Text);
var res3 = (from test in obj.Quest where test.subid == res2 select test).FirstOrDefault();
if (res3 != null)
{
lblqst.Text = res3.question;

opt1.Text = res3.answ1;
opt2.Text = res3.answ2;
opt3.Text = res3.answ3;
opt4.Text = res3.answ4;
}
}
protected void btn_next_Click(object sender, EventArgs e)
{

/*what code to use here?this is the next button where after clicking it next question will display*/
}
Posted
Updated 31-Jan-14 17:30pm
v2
Comments
JoCodes 31-Jan-14 23:34pm    
Tell me one thing, the next question is randomly picked or as per the lblSubject.Text value?
Karthik_Mahalingam 31-Jan-14 23:48pm    
it depends up on the logic of you SQL design..
whether the subid is arranged in incremental order ??
Peter Leow 1-Feb-14 0:20am    
In a real online exam scenario, the sequence of questions appearing on screen of each candidate should be random. For example, candidates A and B will see different questions appearing as Question 1 on their respective screens. Internally, each question will be identified by a unique key. In this way, firstly, the candidates cannot memorize answers by sequence; secondly, it prevents "eye-dropping" from neighboring candidates.

if you subid is formed in incremental order by seed 1 then this will work for you..

C#
protected void btn_next_Click(object sender, EventArgs e)
{
 
int res2 = Convert.ToInt32(lblsubject.Text);
res2 ++;
var res3 = (from test in obj.Quest where test.subid == res2 select test).FirstOrDefault();
if (res3 != null)
{
lblqst.Text = res3.question;
 
opt1.Text = res3.answ1;
opt2.Text = res3.answ2;
opt3.Text = res3.answ3;
opt4.Text = res3.answ4;
}
}


_________
Karthik
 
Share this answer
 
Assuming that the Subject has multiple Questions and Answers.

One simple way to do it can be using Skip and Take Methods of Linq .This makes you to Skip current record and Take the Next one.

Something like

(from test in obj.Quest where test.subid == res2 select test).Skip(RecordNumber-1).Take(1).Single();//or FirstOrDefault


First time the RecordNumber should set to 1 and then on ButtonClick should increment.
And should also reset it if the Subject changes. Pass the RecordNumber as a parameter to the Question() method so that only one method can be reused.

PS: Note that Peter Leow has mentioned a very valid comment . You should consider Randomize record fetch using Order By in Linq query.
Random Order[^]
 
Share this answer
 
v4
Comments
Karthik_Mahalingam 1-Feb-14 0:38am    
Hi Jocodes,
Take(RecordNumber);
if RecordNumber is 5 then it will return 5 questions.
instead of of Take(RecordNumber), you can use Take(1) or FirstorDefault..
what do you think ??
JoCodes 1-Feb-14 1:06am    
Oops you are right Karthik , My intention was that . Thanks alot. Changed the solution .Thanks again for pointing it out. :)
Karthik_Mahalingam 1-Feb-14 11:29am    
Welcome JoCodes :)

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