Hi,
I am developing a website which has feature for online exam. I have 4 radio buttons for 4 options, 1 label for question and next and previous button. When the page is loaded it display the question and 4 answers. When I click on next or previous buttons. How to move to next or previous record in database with datareader or datatable till the last record. I am pasting the code below. It is in ASP.net with C# and SQL Server 2005 Please help me
Code:
public partial class Exam : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RiTech.mdf;Integrated Security=True;User Instance=True");
public DataTable getData()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Exam",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
return dt;
}
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = getData();
lblQuestion.Text = dt.Rows[0]["Question"].ToString();
int count = 0;
Session ["dt"]=dt;
Session["count"] = count;
}
protected void btnNext_Click(object sender, EventArgs e)
{
if (Session["dt"] != null)
{
DataTable dt = (DataTable)Session["dt"];
int count = (int)Session["count"];
count = count + 1;
lblQuestion.Text = dt.Rows[count]["Question"].ToString();
}
}
}