You are on page 1of 4

             &nbsp

;             &nbs
p;             &nb
sp;             &n
bsp;      Silver
<asp:CheckBoxList ID="Silver1" runat="server" RepeatDirection="Horizontal"
Width="737px" >
<asp:ListItem>A1</asp:ListItem>
<asp:ListItem>A2</asp:ListItem>
<asp:ListItem>A3</asp:ListItem>
<asp:ListItem>A4</asp:ListItem>
<asp:ListItem>A5</asp:ListItem>
<asp:ListItem>A6</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:CheckBoxList ID="Silver2" runat="server" RepeatDirection="Horizontal"
Width="737px">
<asp:ListItem>B1</asp:ListItem>
<asp:ListItem>B2</asp:ListItem>
<asp:ListItem>B3</asp:ListItem>
<asp:ListItem>B4</asp:ListItem>
<asp:ListItem>B5</asp:ListItem>
<asp:ListItem>B6</asp:ListItem>
</asp:CheckBoxList>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp; Gold<br />
<asp:CheckBoxList ID="Gold1" runat="server" RepeatDirection="Horizontal"
Width="737px">
<asp:ListItem>C1</asp:ListItem>
<asp:ListItem>C2</asp:ListItem>
<asp:ListItem>C3</asp:ListItem>
<asp:ListItem>C4</asp:ListItem>
<asp:ListItem>C5</asp:ListItem>
<asp:ListItem>C6</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:CheckBoxList ID="Gold2" runat="server" RepeatDirection="Horizontal"
Width="737px">
<asp:ListItem>D1</asp:ListItem>
<asp:ListItem>D2</asp:ListItem>
<asp:ListItem>D3</asp:ListItem>
<asp:ListItem>D4</asp:ListItem>
<asp:ListItem>D5</asp:ListItem>
<asp:ListItem>D6</asp:ListItem>
</asp:CheckBoxList>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp; Platinum<br />
<asp:CheckBoxList ID="Platinum1" runat="server" RepeatDirection="Horizontal"
Width="737px">
<asp:ListItem>E1</asp:ListItem>
<asp:ListItem>E2</asp:ListItem>
<asp:ListItem>E3</asp:ListItem>
<asp:ListItem>E4</asp:ListItem>
<asp:ListItem>E5</asp:ListItem>
<asp:ListItem>E6</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:CheckBoxList ID="Platinum2" runat="server" RepeatDirection="Horizontal"
Width="737px">
<asp:ListItem>F1</asp:ListItem>
<asp:ListItem>F2</asp:ListItem>
<asp:ListItem>F3</asp:ListItem>
<asp:ListItem>F4</asp:ListItem>
<asp:ListItem>F5</asp:ListItem>
<asp:ListItem>F6</asp:ListItem>
</asp:CheckBoxList>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Book"
style="height: 34px" />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class ChooseSeat : System.Web.UI.Page


{

SqlConnection sqlcon = new SqlConnection(@"Data Source=DESKTOP-


FPGG9S0\SQLEXPRESS;Initial Catalog=Online_movie; Integrated security=true;");
private static SqlCommand cmd = new SqlCommand();
private static SqlConnection con = new SqlConnection();

protected void Page_Load(object sender, EventArgs e)


{
}

protected void Button1_Click(object sender, EventArgs e)


{
String str = "";

for (int i = 0; i <= Silver1.Items.Count - 1; i++)


{
if (Silver1.Items[i].Selected)
{

if (str == "")
{

str = Silver1.Items[i].Text;

else
{

str += "," + Silver1.Items[i].Text;

}
}
}

SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-


FPGG9S0\SQLEXPRESS;Initial Catalog=Online_movie; Integrated security=true;");
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Silver values(@Name)",
con);

cmd.Parameters.AddWithValue("@Name", str);
cmd.ExecuteNonQuery();
Response.Write("Your data Sucessfully saved");
Silver1.SelectedIndex = -1;
con.Close();

String str1 = "";

for (int i = 0; i <= Silver2.Items.Count - 1; i++)


{
if (Silver2.Items[i].Selected)
{

if (str1 == "")
{

str1 = Silver2.Items[i].Text;

}
else
{

str1 += "," + Silver2.Items[i].Text;

}
}
}

con.Open();

SqlCommand cmd1 = new SqlCommand("Insert into Silver2 values(@Name)", con);

cmd1.Parameters.AddWithValue("@Name", str1);
cmd1.ExecuteNonQuery();
Response.Write("Your data Sucessfully saved");
Silver2.SelectedIndex = -1;
con.Close();
}
}

Hello,

Made your logic as following way

string strCheckValue = "";

if (chk1.Checked)

strCheckValue = strCheckValue + "," + chk1.Text;

if (chk2.Checked)

strCheckValue = strCheckValue + "," + chk2.Text;

strCheckValue = strCheckValue.TrimStart(',');

You might also like