Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have created a page in asp.net with c# coding . That page is for taking a test . Test contains 10 questions and every question has 4 options . i used separate radio buttons for every options it means for one question's answer i have 4 radio radio buttons. so now i have total 40 radio buttons . Now i want to get the result of the correct answers attempted by the user on the click of submit button . Please someone help me in this .
i didn't use any database....the questions are written on .aspx page and the 4 radio buttons are taken for giving 4 options.
Posted
Updated 25-Mar-14 21:57pm
v2
Comments
Sergey Alexandrovich Kryukov 26-Mar-14 2:21am    
This is done using the operator '+=' :-)
—SA
Member 10682729 26-Mar-14 3:42am    
sorry i didn't understand....can you please show me code for only 1 or 2 questions ???
CPallini 26-Mar-14 4:13am    
Even if you are not using a database, you should have a repository of correct answers (for instance an array). What's the problem in matching the user's answer against such repository?
Member 10682729 26-Mar-14 4:19am    
sorry i am very new to this all ....so i don't know much about this ...
i try this code...in this code i assume that the second radio button is the correct answer for every question....but still this code is giving error...please help me in this

protected void Button2_Click(object sender, EventArgs e)
{
if (RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked && RadioButton14.Checked && RadioButton18.Checked && RadioButton22.Checked && RadioButton26.Checked && RadioButton30.Checked && RadioButton34.Checked && RadioButton38.Checked)
{
Label1.Visible = true;
Label1.Text = "10";
}
else if(RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked && RadioButton14.Checked && RadioButton18.Checked && RadioButton22.Checked && RadioButton26.Checked && RadioButton30.Checked && RadioButton34.Checked)
{
Label1.Visible = true;
Label1.Text = "9";
}
else if (RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked && RadioButton14.Checked && RadioButton18.Checked && RadioButton22.Checked && RadioButton26.Checked && RadioButton30.Checked)
{
Label1.Visible = true;
Label1.Text = "8";
}
else if (RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked && RadioButton14.Checked && RadioButton18.Checked && RadioButton22.Checked && RadioButton26.Checked)
{
Label1.Visible = true;
Label1.Text = "7";
}
else if (RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked && RadioButton14.Checked && RadioButton18.Checked && RadioButton22.Checked)
{
Label1.Visible = true;
Label1.Text = "6";
}
else if (RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked && RadioButton14.Checked && RadioButton18.Checked)
{
Label1.Visible = true;
Label1.Text = "5";
}
else if (RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked && RadioButton14.Checked)
{
Label1.Visible = true;
Label1.Text = "4";
}
else if (RadioButton2.Checked && RadioButton6.Checked && RadioButton10.Checked)
{
Label1.Visible = true;
Label1.Text = "3";
}
else if (RadioButton2.Checked && RadioButton6.Checked)
{
Label1.Visible = true;
Label1.Text = "2";
}
else if (RadioButton2.Checked)
{
Label1.Visible = true;
Label1.Text = "1";
}
else
{
}
}

Assuming that you are using a database to store results, and you stroe a "1" for correct and "0" for incorrect:
SQL
SELECT SUM(Answers) FROM MyTable WHERE UserId=666
Will do it for user 666.

If that isn't how you store things, then there is a huge range of things you could be doing - and we can't tell what they are!
 
Share this answer
 
Comments
Member 10682729 26-Mar-14 4:11am    
thanks for replying me but i am not using any database in this
OriginalGriff 26-Mar-14 4:15am    
Then what are you using to store information?
Member 10682729 26-Mar-14 4:18am    
i want to store only the score of user....not the answers of the questions
OriginalGriff 26-Mar-14 4:46am    
Yes - but the users score is the sum of the correct answers - and you either have to store the correct / incorrect answers *somewhere*, or store the "running total" - otherwise you don;t know.
Remember, I can't see your screen, or access you HDD, so I only get whet you tell me.
So what are you doing when an user answers a question?
Your code has (at least) two problems:
  • It is incorrect.
  • it it clumsy.

You may simple do something like:


C#
RadioButton [] rbGood =
 { RadioButton2, RadioButton6, RadioButton10, RadioButton14, RadioButton18,
   RadioButton22, RadioButton26, RadioButton30, RadioButton34, RadioButton38 };
int total = 0;
for (int k=0; k<9; k++)
{
  if (rbGood[k].Checked) total++;
}
Label1.Visible = true;
Label1.Text = total.ToString();
 
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