Chinna Netha

Chinna Netha

  • 1.9k
  • 278
  • 119.8k

About online examination -multiple choice questions code?

Dec 2 2014 10:33 PM
i gave question and options in data base when i open in browser i got question paper . in that questions i answered only one question and enter finish
but i am getting wrong Result that means backend correct answers adding in that result and showing 
For Example see the below pic and Code
plz help me...
from 2days trying but iam did not get it
 
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
showrec();

}
}
private void showrec()
{
con = new SqlConnection();
con.ConnectionString = str;

cmd = new SqlCommand();
cmd.CommandText = "select TOP 5 * FROM Physics_Question_Paper ";

cmd.Connection = con;
con.Open();

dr = cmd.ExecuteReader();
if (dr.HasRows)
{
grd.DataSource = dr;
grd.DataBind();

}
else
{
Response.Write("No daTa");
}
con.Close();
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
RadioButton r1, r2, r3, r4;
HiddenField hdn;
int count = 0;
string selans = "-1";
for (int i = 0; i < grd.Rows.Count; i++)
{
r1 = (RadioButton)grd.Rows[i].Cells[0].FindControl("rad1");
r2 = (RadioButton)grd.Rows[i].Cells[0].FindControl("rad2");
r3 = (RadioButton)grd.Rows[i].Cells[0].FindControl("rad3");
r4 = (RadioButton)grd.Rows[i].Cells[0].FindControl("rad4");
hdn = (HiddenField)grd.Rows[i].Cells[0].FindControl("hf");
if (r1.Checked)
{
selans = "1";
}
else if (r2.Checked)
{
selans = "2";
}
else if (r3.Checked)
{
selans = "3";
}
else if (r4.Checked)
{
selans = "4";
}

if (hdn.Value == selans)
{
count++;
}
Result.Text = "Score = " + count;
}