I want users to only select one option. That means the user can only check one checkbox then submit the data to database.
<div class="pull-left" style="margin-left:6px;"">
<h4 id="name" class="list-group-item-heading" runat="server">name</h4>
</div>
<br style="margin-bottom:2px; margin-top:2px"/>
<div class="pull-right">
<asp:CheckBox ID="chkname" runat="server" CssClass=" " />
</div>
<div class="pull-left" style="margin-left:6px;">
<h4 id="username" class="list-group-item-heading" runat="server">username</h4>
</div>
<br style="margin-bottom:2px; margin-top:2px"/>
<div class="pull-right">
<asp:CheckBox ID="chkusername" runat="server" CssClass="" />
</div>
protected void Save(object sender, EventArgs e)
{
string userName = Session["UserName"].ToString();
if (chkname.Checked)
{
SaveDetails(userName, name.InnerHtml.Trim());
}
if (chkusername.Checked)
{
SaveDetails(userName, username.InnerHtml.Trim());
}
}
public void SaveDetails(string userName, string Favorites)
{
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Favorite values(@UserName,@Favorites)", con))
{
cmd.Parameters.AddWithValue("@UserName", userName);
cmd.Parameters.AddWithValue("@Favorites", Favorites);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}