How to store radio button data(text) in to database

Posted by Sathiya_Narayanan under ASP.NET on 4/12/2012 | Points: 10 | Views : 31961 | Status : [Member] | Replies : 6
Hi
i have three individual radio buttons in a form when i select any one radio button its selected radio button text should be save in sql database.
how to perform this...
pls give any examples







Thanks

SATHIYANARAYANAN


Responses

Posted by: Sakthi.Singaravel on: 4/12/2012 [Member] Silver | Points: 25

Up
0
Down
hi sathiya,

See this our forum old query...

http://www.dotnetfunda.com/forums/thread8937-storing-radio-button-and-checkbox-value-in-database.aspx

Regards,
Singaravel M

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

Posted by: Self-Innovator on: 4/12/2012 [Member] Bronze | Points: 25

Up
0
Down
<asp:RadioButtonList ID="rblGender" runat="server" RepeatDirection="Horizontal">

<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="2"></asp:ListItem>
</asp:RadioButtonList>


OnClick Event on button or watever u wish
btnIns_Click(string pGender,)
{
SQlConnection cnn = new SqlConnection(Conn);
Sqlcommandcmd=new SqlCommand("sp_InsPersonGender", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pGender", pGender);
Sqldataadapter ada = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
}

try somthing lik this

Join Hands Change lives
Thanks & Regards
Straight Edge Society

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

Posted by: Yuvaopens on: 5/8/2012 [Member] Starter | Points: 25

Up
0
Down
Radiobuttonname.selectedvalue;

Yuvaraj.S

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

Posted by: Somasundaram on: 5/9/2012 [Member] Starter | Points: 25

Up
0
Down
If u want to save Text field -
use
RadioButton.SelectedItem.Text;

if u want to save Value Field into db-
use
RadioButton.SelectedValue;

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

Posted by: Sekar.C on: 5/9/2012 [Member] Starter | Points: 25

Up
0
Down
if(RadioButtonList1.SelectedItem.Text=="R1")

{
value = "R1";
}
else if (RadioButtonList1.SelectedItem.Text == "R2")
{
value = "R2";
}
else
{
value = "R3";
}
TextBox1.Text = value;


Regards
Sekar.c

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

Posted by: Sriramnandha on: 5/23/2012 [Member] Starter | Points: 25

Up
0
Down
ASPX

<p>

&nbsp;</p>
<p>
<asp:RadioButton ID="RadioButton1" runat="server" Text="FIRST"
AutoPostBack="True" oncheckedchanged="RadioButton1_CheckedChanged" />
</p>
<p>
<asp:RadioButton ID="RadioButton2" runat="server" Text="SECOND"
AutoPostBack="True" />
</p>
<p>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
</p>


ASPX.CS

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)

{
if (RadioButton1.Text == "FIRST")
{
string connectionstring = "CONNECTIONSTRING";

SqlConnection con = new SqlConnection(connectionstring);
string sqlinsert = "insert into MYRADIO values ('" + RadioButton1.Text + "')";
con.Open();
SqlCommand cmd = new SqlCommand(sqlinsert, con);
cmd.ExecuteNonQuery();
con.Close();
}
else
{

string connectionstring = "CONNECTIONSTRING";

SqlConnection con = new SqlConnection(connectionstring);
string sqlinsert = "insert into MYRADIO values ('" + RadioButton2.Text + "')";
con.Open();
SqlCommand cmd = new SqlCommand(sqlinsert, con);
cmd.ExecuteNonQuery();
con.Close();

}
}
}
}


HOPE THIS WILL HELP

REGARDS


sriram

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

Login to post response