Ok you can try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class RadioButtonBinding : System.Web.UI.Page
{
protected int QuestionNo
{
get
{
return Session["QuestionNo"] != null ? (int)Session["QuestionNo"] : 1;
}
set
{
Session["QuestionNo"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dataTable = new DataTable();
dataTable = GetData("SELECT [Q.NO],[QUESTION],[A],[B],[C],[D],[ANS] FROM ONLINETEST WHERE [Q.NO] = " + this.QuestionNo + "");
rblOptions.AppendDataBoundItems = true;
if (dataTable.Rows.Count > 0)
{
lblQuestion.Text = dataTable.Rows[0]["Q.NO"].ToString() + ". " + dataTable.Rows[0]["QUESTION"].ToString();
rblOptions.Items.Add(new ListItem { Text = "a." + dataTable.Rows[0]["A"].ToString(), Value = dataTable.Rows[0]["A"].ToString() });
rblOptions.Items.Add(new ListItem { Text = "b." + dataTable.Rows[0]["B"].ToString(), Value = dataTable.Rows[0]["B"].ToString() });
rblOptions.Items.Add(new ListItem { Text = "c." + dataTable.Rows[0]["C"].ToString(), Value = dataTable.Rows[0]["C"].ToString() });
rblOptions.Items.Add(new ListItem { Text = "d." + dataTable.Rows[0]["D"].ToString(), Value = dataTable.Rows[0]["D"].ToString() });
}
}
}
protected void OnNextClicked(object sender, EventArgs e)
{
//Here if you want you can write the code to save the answer selected by user in the database
this.QuestionNo++;
//Here you have to again redirect to the same page
Response.Redirect("~/RadioButtonBinding.aspx");
}
private DataTable GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}