how to save radio button preference

Posted by Nileshkhochare under C# on 3/12/2013 | Points: 10 | Views : 2392 | Status : [Member] | Replies : 5
I am creating exam software using C#.
It consist a form having one question and five options (radio buttons) for that question and Next and Previous buttons.
Now i have written code for inserting and updating user's options in database.When user click on radio button for selecting answer that option get saved in database but after some time when user comes on that same question again,that radio button selection not remain as it is.how to solve this.pls help.




Responses

Posted by: Raj.Trivedi on: 3/13/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Nilesh,

Can you paste the code for retrieving the values when you are coming back to the question.

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Nileshkhochare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
http://stackoverflow.com/questions/103765/how-do-i-persist-the-value-of-a-label-through-a-response-redirect

Are you redirecting to any other page using the next and previous button??

____________
www.flickr.com/photos/psdesigner/

Nileshkhochare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
I dont know whether it is good technique or not but its just a suggestion. You can maintain session information using different session variables.

ex
Session("1") = 4
Session("2") = 5
.
.
.
Like this. You can assign session for each question. and on load of the question use this session value and assign the select index for radio buttons

____________
www.flickr.com/photos/psdesigner/

Nileshkhochare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nileshkhochare on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
*************** coding of retrieving values from table***********************

private void buttonnext_Click(object sender, EventArgs e)
{
this.BindingContext[ds.Tables[0]].Position -= 1;
con.Open();
SqlDataAdapter Adpt = new SqlDataAdapter("Select user_ans from MyNewSet where que_no= '" + label2.Text + "'", con);
Adpt.Fill(ds);
DataTable dt = ds.Tables[0];
try
{

if ((dt.Rows[0][2]).ToString().Equals((dt.Rows[0][7]).ToString()))
{
radioButton1.Checked = true;
}

if ((dt.Rows[0][3]).ToString().Equals((dt.Rows[0][7]).ToString()))
{
radioButton2.Checked = true;
}

if ((dt.Rows[0][4]).ToString().Equals((dt.Rows[0][7]).ToString()))
{
radioButton3.Checked = true;
}

if ((dt.Rows[0][5]).ToString().Equals((dt.Rows[0][7]).ToString()))
{
radioButton4.Checked = true;
}
}
catch(Exception)
{

}

con.Close();
}

Nileshkhochare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nileshkhochare on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
but as per my knowledge,we can maintain session variable in asp.net only not in c#.net.Let me know how to store sessions in c#.net plz..
thanks..

Nileshkhochare, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response