How do i create checkbox to insert all selected items and insert into table with reciept number.
This code below inserts checkbox items like example below
C_ID Item
---------------------------------------
1 cake,bread,icecream,fruits
---------------------------------------
But i want it this way
Example
C_ID Recipt Item
1 001 cake
2 001 bread
3 001 icecream
4 002 milk
5 002 chocolet
So the idea is to insert this items with their customer reciepts, the reciept shows that two reciepts were issued to two customers. Thats the idea.
HTML
<asp:CheckBoxList ID="chkHobbies" runat="server">
</asp:CheckBoxList>
<br />
<asp:Button ID="btnInsert" runat="server" Text="Button" OnClick = "UpdateHobbies" />
CODE
private void PopulateHobbies()
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["DB"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select * from Items";
cmd.Connection = conn;
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
ListItem item = new ListItem();
item.Text = sdr["Item"].ToString();
item.Value = sdr["C_ID"].ToString();
item.Selected = Convert.ToBoolean(sdr["IsSelected"]);
chkHobbies.Items.Add(item);
}
}
conn.Close();
}
}
}