select multiple value and asp check box list select true
I have a some problem.I have saved values in a single column like E1,E2 with Checkbox list.
Now i would like to true the value in asp.net CheckBoxList control where E1 and E2 must be selected when page Load.In Checkbox List Edit Template E1 E2 E3 E4 E5.When Save Mutiple checkbox not check.
string connStr = ConfigurationManager.ConnectionStrings["Thcon"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
txtbookinid.Text = boking.GetMaxID().ToString();
GetSec();
}
protected void Button1_Click(object sender, EventArgs e)
{
boking.Bookid = Convert.ToInt32(txtbookinid.Text);
string date = ddlday.Text + "/" + ddlmth.Text + "/" + ddyear.Text;
string time = ddlshowtime.Text;
CheckBoxList chk = CheckBoxList1.FindControl("CheckListBoxList1") as CheckBoxList;
string sno = "";
for (int i = 0; i < chk.Items.Count; i++)
{
if (chk.Items[i].Selected)
{
sno += chk.Items[i].Value + ",";
}
}
if (CheckBoxList1.Enabled == true)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=TheatreDB;integrated security=true");
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.Parameters.Clear();
cmd.CommandText = "INSERT INTO [TBL_Bookin] ([bookid],[userid],[moviename],[seatno],[date],[time]) VALUES (@id,@userid,@moviename,@seatno,@date,@time)";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@id", txtbookinid.Text);
cmd.Parameters.AddWithValue("@userid", Session["name"].ToString());
cmd.Parameters.AddWithValue("@moviename", ddlmovielist.SelectedItem.Text);
cmd.Parameters.AddWithValue("@seatno", sno);
cmd.Parameters.AddWithValue("@date", date);
cmd.Parameters.AddWithValue("@time", time);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
}
Response.Redirect("ViewSeating.aspx");
}
public void GetSec()
{
CheckBoxList chbx = CheckBoxList1.FindControl("CheckBoxList1") as CheckBoxList;
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=TheatreDB;integrated security=true");
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT seatno FROM TBL_Bookin";
cmd.Parameters.Clear();
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ListItem currentChbx = chbx.Items.FindByText(reader["seatno"].ToString());
if (currentChbx != null)
{
currentChbx.Selected = true;
currentChbx.Enabled = false;
}
}
con.Close();
}