using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Web.Security; using System.Data; public partial class OnlineExam : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { if (Session["result"] == null) { Session["result"] = '0'; } Result.Text = Session["result"].ToString(); if (Session["Number"] == null) { Session["Number"] = 1; } Q.Text = Session["Number"].ToString(); con.Open(); SqlCommand cmd = new SqlCommand("Select * from Questions where QuestionNo = '" + Q.Text + "'",con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { Questions.Text = dr["Question"].ToString(); Option1_lbl.Text = dr["Ans1"].ToString(); Option2_lbl.Text = dr["Ans2"].ToString(); Option3_lbl.Text = dr["Ans3"].ToString(); Option4_lbl.Text = dr["Ans4"].ToString(); } con.Close(); con.Open(); SqlCommand cmd1 = new SqlCommand("Select * from Answers where QuestionNo = '" + Q.Text + "'",con); SqlDataReader dr1 = cmd1.ExecuteReader(); if (dr1.Read()) { Answer.Text = dr1["Answer"].ToString(); } con.Close(); } protected void Option1_rb_CheckedChanged(object sender, EventArgs e) { if (Option1_rb.Checked) { OptionAns.Text = Option1_lbl.Text; } } protected void Option2_rb_CheckedChanged(object sender, EventArgs e) { if (Option2_rb.Checked) { OptionAns.Text = Option2_lbl.Text; } } protected void Option3_rb_CheckedChanged(object sender, EventArgs e) { if (Option3_rb.Checked) { OptionAns.Text = Option3_lbl.Text; } } protected void Option4_rb_CheckedChanged(object sender, EventArgs e) { if (Option4_rb.Checked) { OptionAns.Text = Option4_lbl.Text; } } protected void Next_btn_Click(object sender, EventArgs e) { int i=0; if (Session["Number"] == null) { Session["Number"] = '0'; } else { i = int.Parse(Session["Number"].ToString()); } if (OptionAns.Text==Answer.Text) { int res; res = int.Parse(Session["result"].ToString()) + 1; Session["result"] = res; } if (i <= 5) { Session["Number"] = ++i; } else { Response.Redirect("Result.aspx"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)