hi,
I am designing Online Test Creation Using asp.net(C#). in that question display should be like this;

.....................Question.............................
O opt1
O opt2
O opt3
O opt3

prev next (buttons)

my questions and Options had saved in two Sql tables.

Question(idquestion,Qname,Answer,Qtype) idQuestion is primary key

Answer_Detail(idAnswerDetail,idquestion,options) idAnswerDetail is primary key and idquestion is Foreign Key

how can i display one question at a time randomly, if i have 100 questions in my database. on next button click i have to get another
question and on previous button click i have to go back to previous Question. which control i have to use for this one. i have to select
one radio button among given following four options.
i used grid view,details view ..etc but i could not get the above format.. how can i do it, because i have show which Option is selected during Prev and next button clicks.. i have to store all these question ids and which option is selected into database....

Dani AI

Generated

A concise, robust pattern for this problem is: pick a fixed random order once at test start, keep that order server-side, and store per-question answers server-side while the user navigates. That avoids duplicates, preserves the selected option on Prev/Next, and makes final persistence simple. 's VB.NET sample (VS2008) shows the same logic flow and can be ported to C#; note that VS2005 may need AJAX support as mentioned by and discussed by .

Key steps (workflow):

  • At test start generate a randomized ordered list of question IDs and save it server-side (Session or a temporary TestAttempt row). For SQL Server a quick seed is:
    SELECT TOP (@N) idQuestion FROM Questions ORDER BY NEWID();
  • Keep a numeric index (current position) and a dictionary/map of answers keyed by question ID in Session. Use a Label for question text and a RadioButtonList for options; Prev/Next only change the index and re-bind the controls.
  • Before moving away from a question, save the selected value into the Session answers map. When binding a question, set RadioButtonList.SelectedValue from that map so the previously chosen option is shown.

Minimal C# examples (illustrative):

// on start
Session["QOrder"] = GetRandomQuestionIds(n);
Session["QIndex"] = 0;
Session["Answers"] = new Dictionary<int,int>();

// on load question
var ids = (List<int>)Session["QOrder"];
int qid = ids[(int)Session["QIndex"]];
BindQuestion(qid); // bind label + RadioButtonList
if(((Dictionary<int,int>)Session["Answers"]).TryGetValue(qid,out int sel))
  rblOptions.SelectedValue = sel.ToString();

Persistence and tips:

  • Save answers to a TestAttempt/TestAnswer table at finish (or auto-save per question). Use parameterized queries and server-side validation.
  • Avoid big ViewState objects—Session or DB is safer. For very large pools, ORDER BY NEWID() can be slow; pre-generate the sample or use an efficient random-sampling strategy.
  • If config/runtime errors appear (as experienced), enable detailed errors or check web.config to get the exact failure line for faster troubleshooting.

Recommended Answers

All 8 Replies

I have made a similar project. You might want to see the code-

In case you have any doubts about the code, do ask here.

Its just that the code is in VB.NET. I guess you can still figure out the logic

hi tuse,
i have seen u r web link and downloaded u r project.I am getting error in web.config as

"Child nodes not allowed."

hi greeny,

could you please enable debugging in your web.config and tell me where exactly you are getting the error?

tuse, your online test solution looks interesting. I had downloaded a copy and was wondering which version of vs did you use for development. v2 or 3.0?

Hi jamello!

Its made in Visual Studio 2008 using .NET Framework 3.5

ps- You need to have AJAX in order to get it working in VS 2005

aww..!
I use vs 2005. but would upgrade soon.:(

Hi jamello!

Its made in Visual Studio 2008 using .NET Framework 3.5

ps- You need to have AJAX in order to get it working in VS 2005

thanks for your codding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.