creating online mcq paper

Swappy_Gaj
Posted by Swappy_Gaj under ASP.NET category on | Points: 40 | Views : 606
table:
id int,queno-int,que-varchar,option1-varchar,option2-varchar,correctans-varchar-marks-int,subject-varchar

public static int cnt = 0;
int cal = 0;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{

if (cnt != null)
{
cnt = 0;
}
SqlConnection con=new SqlConnection(@"Data Source=COMP-3\HARSHAL;Initial Catalog=studentattendance;User ID=sa;Password=digital_1");
con.Open();
ArrayList a = new ArrayList();
ArrayList b = new ArrayList();

foreach (DataListItem item in DataList1.Items)
{
RadioButton rb1 = (RadioButton)item.FindControl("RadioButton1");
RadioButton rb2 = (RadioButton)item.FindControl("RadioButton2");
if (rb1.Checked)
{
a.Add(rb1.Text);
//Label l = (Label)item.FindControl("Label2");
//cal += Convert.ToInt32(l.Text);
// Response.Write(rb1.Text);
}
else if (rb2.Checked)
{
a.Add(rb2.Text);
//Label l1 = (Label)item.FindControl("Label2");
//cal += Convert.ToInt32(l1.Text);
//Response.Write(rb2.Text);
}
}

//priting total marks
// Response.Write(cal);

//foreach (var item in a)
//{
// Response.Write(item.ToString());
//}

//getting actual answers
SqlCommand cmd = new SqlCommand("select * from OEX where subject='C'", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
b.Add(dr["correctans"].ToString());
}

//comparing answers
foreach (var item in a)
{
if (b.Contains(item))
{
cnt++;

}
}

//printing result
//// Response.Write("You have answered" + cnt + "correctly out of" + a.Count);
Response.Write("<span style= 'color:red'>You have answered" + cnt + "correctly out of" + a.Count);


//getting correct marks
SqlConnection con2 = new SqlConnection(@"Data Source=COMP-3\HARSHAL;Initial Catalog=studentattendance;User ID=sa;Password=digital_1");
SqlConnection con3 = new SqlConnection(@"Data Source=COMP-3\HARSHAL;Initial Catalog=studentattendance;User ID=sa;Password=digital_1");
con2.Open();
con3.Open();
int y=0;

foreach (DataListItem item in DataList1.Items)
{

RadioButton r1 = (RadioButton)item.FindControl("RadioButton1");
RadioButton r2 = (RadioButton)item.FindControl("RadioButton2");
if (r1.Checked)
{
SqlCommand cmd1=new SqlCommand("select marks from OEX where correctans='"+r1.Text+"'",con2);
int correctanstotal = Convert.ToInt32(cmd1.ExecuteScalar());

y=y+correctanstotal;

}




}
// ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "k", "alert('You scored'"+y+"' out of '"+a.Count+"')", true);
//ScriptManager.RegisterStartupScript(Page, GetType(), "MyScript", "alert('You scored'" + y + "' out of '" + a.Count + "');", true);


//get total marks of subject
SqlConnection con4 = new SqlConnection(@"Data Source=COMP-3\HARSHAL;Initial Catalog=studentattendance;User ID=sa;Password=digital_1");
con4.Open();
SqlCommand cmd4 = new SqlCommand("Select sum(marks) from OEX where subject='C'", con4);
int s = Convert.ToInt32(cmd4.ExecuteScalar());
//Response.Write("You scored"+y+" out of "+s);
Response.Write("<span style= 'color:red'>You scored"+y+" out of "+s);



}

Comments or Responses

Login to post response