Hi Team,
how do first check and uncheck the check box, and how do i save the content on the check to the database.
Regard
George
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jun 14, 2012, 2:02 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Checkbox_values_insert._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Checkbox_values_insert
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_register_Click(object sender, EventArgs e)
{
if (chk1.Checked == true)
{
SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@Name,@Email,@Gender)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Email", txtEmail.Text);
com.Parameters.AddWithValue("@gender", chk1.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
clear();
}
else
{
SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@Name,@Email,@Gender)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Email", txtEmail.Text);
com.Parameters.AddWithValue("@gender", chk2.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
clear();
}
}
void clear()
{
txtName.Text = "";
txtEmail.Text = "";
chk1.Checked = false;
chk2.Checked = false;
}
}
}
Thanks
If this post helps you mark it as answer
george wambuiPosted Jun 14, 2012, 1:32 AM
Regard
george
rakesh chaudhariPosted Jun 14, 2012, 1:23 AM