public partial class RadioButton : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Enabled = false;
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
TextBox1.Enabled = true;
TextBox1.Text = "I Am Male";
string value = RadioButton1.Text;
SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=practice;integrated security=true;");
SqlCommand sqlcomm = new SqlCommand("insert into insertvalue(radiobtnvalue) values(@a)", sqlconn);
sqlconn.Open();
sqlcomm.Parameters.Add("@a", SqlDbType.VarChar, 10).Value = value.ToString();
sqlcomm.ExecuteNonQuery();
sqlconn.Close();
Response.Write("Value Saved");
}
}
Source-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioButton.aspx.cs" Inherits="RadioButton" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 87px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2">
Select Value</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
oncheckedchanged="RadioButton1_CheckedChanged" Text="Male" />
</td>
</tr>
<tr>
<td class="style2">
Name</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Sql part-
create table insertvalue(radiobtnvalue varchar(10))
select * from insertvalue