Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
online exam : suppose having 100 question in db.

in client side one question per page have to display..on previous and next button click question display.

what logic i should use ?


!? > every button click call db to get 1 new question ??
!? > what if out of 100 ..30 random question get if required 30 question (same one page one question)

What I have tried:

currently not get any solution.
i don't know how to start.
Posted
Updated 11-Jan-18 0:28am
v2

1 solution

You should load x questions into DataTable[^] or DataSet[^] object, where x means: as many as you wish or requires.
If you want to get 30 random questions, you may use Take()[^] Linq method:
C#
var rand = new Random();   
var result = yourDataTable.AsEnumerable().OrderBy(r => rand.Next()).Take(30); //get 30 records from datatable

or server side solution: Selecting Rows Randomly from a Large Table[^]

When you've got a set of questions, you may go to the next question by using Skip()[^] and Take() together:

C#
var nextQuestion = yourDataTable.AsEnumerable().Skip(currentIndex).Take(1);
//currentIndex -> currently displayed question


Now, you,ve got an idea how to achieve your goals. Let's go to work!
Good luck!
 
Share this answer
 
Comments
Jaydeep Shah 12-Jan-18 1:08am    
yes i got idea ! Thank you so much.. but one more question what query i write for preview button ...where i required attempt question with selected answer.
Maciej Los 12-Jan-18 13:49pm    
Think of it! You have to store proper data in set of variable, then you'll be able to check the answer.

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