Click here to Skip to main content
16,004,406 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when question are show in radio buttons in quiz form next button click next question will be appear . how can i check radio button option click and question correct ans that store in data base, and after taking quiz how can i show result.

What I have tried:

 private static int  question_id=0;
 protected void Page_Load(object sender, EventArgs e)
        {
            
            GetData();
           
        }

<pre> private DataTable GetData()
        {
            DataTable dt = new DataTable();
            SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=Quiz_system;Integrated Security=True");
            try
            {
                connection.Open();
                SqlCommand sqlCmd = new SqlCommand("Select question,op1,op2,op3,op4 From tbl_question_bank  where course_name='" + Session["coursename"] + "'" , connection);
                SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
                sqlDa.Fill(dt);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                string msg = "Fetch Error:";
                msg += ex.Message;
                throw new Exception(msg);
            }
            finally
            {
                connection.Close();
            }
            return dt;
        }

<pre> protected void btninsert_Click(object sender, EventArgs e)
        {
            DataTable dt = GetData();
            Session["dt"] = dt;
            if(Session["dt"]!=null && question_id < dt.Rows.Count)
            {
                lblquestion.Text = dt.Rows[question_id]["question"].ToString();// questions.Add(red[0]);
                rdb1.Text = dt.Rows[question_id]["op1"].ToString();// opt1.Add(red[1]);
                rdb2.Text = dt.Rows[question_id]["op2"].ToString();// opt2.Add(red[2]);
                rdb3.Text = dt.Rows[question_id]["op3"].ToString(); //opt3.Add(red[3]);
                rdb4.Text = dt.Rows[question_id]["op4"].ToString(); //opt4.Add(red[4]);
                
            }
          question_id++;
            //else
            //{
            //    Response.Write("quizz end");
            //}
        }

<
Posted
Updated 4-May-17 20:56pm
Comments
[no name] 4-May-17 17:27pm    
You get the data from your database and actually do something with it instead throwing it away after you query it.

You can display all questions and radio buttons in one page.First by getting all questions list in viewbag,display one by one questions on view.and below each question show radio button and give id to ech radio button which should increase automatically.You can do this by for loop.After this in controller method use formcollection to get selected answers list.And compare two list and show result
 
Share this answer
 
You should have mapped Question_ID and corrent Answer_ID in your database as a master data.

Once your application started user will check one radio button.
After click on next button you have to store User_ID, Question_ID and Answer_ID and table after end of the application you can calculate correct answers and incorrect answers
 
Share this 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