I have 4 radio buttons to choose as an answer and in databse a table named quser with the fields :
qid,uans,result.
I am thinking to do it in this way:
When the user clicks on his answer i.e. radiobutton then it should get stored in the uans field.
How to do this?
I am the beginner so don't have much idea just tried it in this way:
con.Open()
cmd = New SqlCommand("insert into quser (uans) values('" + RadioButton1.Checked + "'||'" + RadioButton2.Checked + "'||'" + RadioButton3.Checked + "'||'" + RadioButton4.Checked + "' )", con)
cmd.ExecuteNonQuery()
And am also confused whether to use individual radiobuttons or directly radiolist?
Not getting any further reply on this link
http://forums.asp.net/t/1790367.aspx/1?How+to+add+this+values+from+radiobutton+
So, I am reposting it again.
I am interested in learning this and stucked up with this ..can somebody help me?
It allows to store the values but at the same point it allows user again to choose the option.
If the user changes his decision and clicks on other option then that option gets store in the database as new record.
Is there way to replace the old record instead of adding it as new one?
IAmateur
Member
96 Points
388 Posts
What is the correct syntax ?
Apr 11, 2012 05:52 AM|LINK
I have 4 radio buttons to choose as an answer and in databse a table named quser with the fields :
qid,uans,result.
I am thinking to do it in this way:
When the user clicks on his answer i.e. radiobutton then it should get stored in the uans field.
How to do this?
I am the beginner so don't have much idea just tried it in this way:
con.Open()
cmd = New SqlCommand("insert into quser (uans) values('" + RadioButton1.Checked + "'||'" + RadioButton2.Checked + "'||'" + RadioButton3.Checked + "'||'" + RadioButton4.Checked + "' )", con)
cmd.ExecuteNonQuery()
And am also confused whether to use individual radiobuttons or directly radiolist?
Not getting any further reply on this link
http://forums.asp.net/t/1790367.aspx/1?How+to+add+this+values+from+radiobutton+
So, I am reposting it again.
I am interested in learning this and stucked up with this ..can somebody help me?
Time to go Long way...
amitpatel.it
Star
7966 Points
1865 Posts
Re: What is the correct syntax ?
Apr 11, 2012 05:58 AM|LINK
Here you can use RadiobuttonList controls so when you select any of the radio button you can easily get it Radiobuttonobject.Selectedvalue.
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
IAmateur
Member
96 Points
388 Posts
Re: What is the correct syntax ?
Apr 11, 2012 06:04 AM|LINK
Amit
So,how to write the code syntax?
I mean what I wrote above is that correct?
Time to go Long way...
yrb.yogi
Star
14460 Points
2402 Posts
Re: What is the correct syntax ?
Apr 11, 2012 06:11 AM|LINK
//simple methods if(RadioButton1.Checked) { cmd = New SqlCommand("insert into quser (uans) values('" + RadioButton1.Text + "', con) } else if(RadioButton2.Checked) { cmd = New SqlCommand("insert into quser (uans) values('" + RadioButton2.Text + "', con) } else if(RadioButton3.Checked) { cmd = New SqlCommand("insert into quser (uans) values('" + RadioButton3.Text + "', con) } else if(RadioButton4.Checked) { cmd = New SqlCommand("insert into quser (uans) values('" + RadioButton4.Text + "', con) } cmd.ExecuteNonQuery() //or use radio button list //below code cmd = New SqlCommand("insert into quser (uans) values('" + RadioButtonList.SelectedValue + "', con) cmd.ExecuteNonQuery().Net All About
IAmateur
Member
96 Points
388 Posts
Re: What is the correct syntax ?
Apr 11, 2012 06:37 AM|LINK
Yogi
This is allowing the user to click on all buttons. How to make user click on only 1 button and not all.
Time to go Long way...
yrb.yogi
Star
14460 Points
2402 Posts
Re: What is the correct syntax ?
Apr 11, 2012 06:42 AM|LINK
Instead of radiobutton use radiobutton list to allow user to select only one radionbutton.
http://www.w3schools.com/aspnet/control_radiobuttonlist.asp
.Net All About
yrb.yogi
Star
14460 Points
2402 Posts
Re: What is the correct syntax ?
Apr 11, 2012 06:42 AM|LINK
Instead of radiobutton use radiobutton list to allow user to select only one radionbutton.
http://www.w3schools.com/aspnet/control_radiobuttonlist.asp
.Net All About
IAmateur
Member
96 Points
388 Posts
Re: What is the correct syntax ?
Apr 11, 2012 06:57 AM|LINK
Thanks Yogi. I used radiobuttonlist and its working fine :)
Time to go Long way...
IAmateur
Member
96 Points
388 Posts
Re: What is the correct syntax ?
Apr 13, 2012 11:35 AM|LINK
yrb.yogi
It allows to store the values but at the same point it allows user again to choose the option.
If the user changes his decision and clicks on other option then that option gets store in the database as new record.
Is there way to replace the old record instead of adding it as new one?
Time to go Long way...