can any one tell me how to insert checked item to a database..i have following code.
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
SqlConnection con = new SqlConnection(strConnection);
con.Open();
cmd = new SqlCommand("Insert Into UserCreation(FullName,UserName,Email,PhoneNo,RegionID,StateId,CityID,Password,SecurityQue,SecurityAns,MenuMasterID) VALUES(@FullName,@UserName,@Email,@PhoneNo,@RegionID,@StateId,@CityID,@Password,@SecurityQue,@SecurityAns,@MenuMasterID)", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@FullName", txtFullname.Text);
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@PhoneNo", txtPhoneno.Text);
cmd.Parameters.AddWithValue("@RegionID", DdlRegion.SelectedValue);
cmd.Parameters.AddWithValue("@StateId", DdlState.SelectedValue);
cmd.Parameters.AddWithValue("@CityID", DdlCity.SelectedValue);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@SecurityQue", txtSecurityquestion.Text);
cmd.Parameters.AddWithValue("@SecurityAns", txtSecurityanswer.Text);
cmd.Parameters.AddWithValue("@MenuMasterID",chkmenuRights.SelectedItem);
cmd.ExecuteNonQuery();
con.Close();
ClientScript.RegisterStartupScript(this.GetType(), "Hello", "alert('Successfully created a user');", true);
txtFullname.Text = "";
txtUserName.Text = "";
txtEmail.Text = "";
txtPhoneno.Text = "";
txtPassword.Text = "";
txtConfirmpassword.Text = "";
txtSecurityquestion.Text = "";
txtSecurityanswer.Text = "";
DdlRegion.SelectedIndex = 0;
DdlState.SelectedIndex = 0;
DdlCity.SelectedIndex = 0;
}
pls help me.
thanx.
pls help me.
thanx.
amol shelkePosted Apr 8, 2012, 12:01 AM
SenthilkumarPosted Apr 7, 2012, 10:13 AM
Satyapriya posted entire code for sample of checkbox.
I think this user facing problem with the checkboxlist.
Satyapriya NayakPosted Apr 7, 2012, 7:56 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Counter_check_data.WebForm1" %>
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 Counter_check_data
{
public partial class WebForm1 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
protected void Button1_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(Name,Category) values(@Name,@Category)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Category", chk1.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
clear();
}
}
void clear()
{
txtName.Text = "";
chk1.Checked = false;
}
}
}
Thanks
If this post helps you mark it as answer