Please refer the below example. This will give you better idea.
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void btn_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=database; Integrated Security=TRUE;"))
{
using (SqlCommand command = new SqlCommand("Insert into table(Item,Active) values(@Item,@Active);", connection))
{
command.Parameters.AddWithValue("@Item", DropDownList1.SelectedItem.Text);
command.Parameters.AddWithValue("@Active", radioButton1.Checked.ToString());
connection.Open();
command.ExecuteNonQuery();
connection.Close();
lbl.Text = "Item added to database";
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lbl" runat="server"></asp:Label><br />
Item:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Item1"></asp:ListItem>
<asp:ListItem Text="Item2"></asp:ListItem>
</asp:DropDownList><br />
Active: <asp:RadioButton ID="radioButton1" runat="server" />
<asp:Button ID="btn" runat="server" Text="Test" OnClick="btn_Click" />
</div>
</form>
</body>
</html>