Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
This is my code.

C#
public void GetNextQuestion(int next)
   {
       dt = (DataTable)ViewState["Datatable"];
       dr = dt.Rows[next];
       lblQuestion.Text = "Q." + Session["counter"] + "  " + dr["Qn"].ToString();
      // RblOption.ClearSelection();
       RblOption.Items.Clear();
       RblOption.Items.Add(dr["option1"].ToString());
       RblOption.Items.Add(dr["option2"].ToString());
       RblOption.Items.Add(dr["option3"].ToString());
       RblOption.Items.Add(dr["option4"].ToString());
       //CheckAnswer();



//       Session["RblOption"] = (string)RblOption.SelectedValue;

   }


C#
public void GetPrevQuestion(int prev)
    {
        dt = (DataTable)ViewState["Datatable"];
        dr = dt.Rows[prev];
        //Session["RblOption"] = (string)RblOption.SelectedValue;
        //RblOption.SelectedValue = (string)Session["RblOption"];
        lblQuestion.Text = "Q." + Session["counter"] + "  " + dr["Qn"].ToString();
       // RblOption.ClearSelection();
        RblOption.Items.Clear();
        RblOption.Items.Add(dr["option1"].ToString());
        RblOption.Items.Add(dr["option2"].ToString());
        RblOption.Items.Add(dr["option3"].ToString());
        RblOption.Items.Add(dr["option4"].ToString());




        if (prev != 0)
        {
            BtnPrev.Visible = true;
        }
        BtnNext.Visible = true;
    }
Posted
Comments
KALYANI BIBIN 6-May-14 0:36am    
Wat should i do to maintain the selection in radiobutton if it has already selected. I am just a beginner to project. So pls help me.

1 solution

You need to store previous or next question answer in somewhere so that you can fetch it whenever required. In my project I saved it in database.
 
Share this answer
 
Comments
KALYANI BIBIN 6-May-14 0:44am    
yes i have stored it in db table with columns QuestionId,UserOption(int),
User_Id . but how it should use?
MNamrata 6-May-14 0:55am    
See when user not attempted question there is no entry in database when he answered question then we will get record against that questionID. It means when I click on answered question then send that questionid to db and fetch answer and bind it to radiobuttonlist.

ds=GetAnswers(UserID,QuestionID,ExamID);

rbl.DataSource = ds.tables[0];
rbl.DataTextField = "OptionName";
rbl.DataValueField = "QOptionID";
rbl.DataBind();
KALYANI BIBIN 6-May-14 3:25am    
i have tried it but not getting item as selected.
it tried the below code to make the option as selected
RblOption.SelectedIndex = x;
x is the userOption column in database table. x is getting the value from database. But RblOption.SelectedIndex is still -1.
MNamrata 6-May-14 4:58am    
foreach (ListItem li in rbl.Items)
{
if (li.Value == X)
{
li.Selected = true;
break;
}
}
KALYANI BIBIN 9-May-14 2:01am    
Yes i got it. Thanks namratamane .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900