Hi
I am trying to make the check box list for menu system I am working on. I try to make the user to select items using a set of check boxes as show in html code and show him/her the total number of items that is selected. but I want to ask how can show the number of individual items
<form id="form1" runat="server">
<div style="width:930px">
<p>Add your item to your cart</p>
<asp:CheckBoxList ID="itemListchk" runat="server"
>
<asp:ListItem Value="1">Tea</asp:ListItem>
<asp:ListItem Value="1">Coffee</asp:ListItem>
<asp:ListItem Value="1">Cappuccino</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click"
Text="Add to Cart" />
</div>
</form>
public partial class ShoppingCart : System.Web.UI.Page
{
Cart cart = new Cart();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAdd_Click(object sender, EventArgs e)
{
//CheckBoxList target = (CheckBoxList)sender;
int totalNumberItems = 0;
HttpCookie cookie = new HttpCookie("itemListchk_SelectedItems");
cookie.Expires = DateTime.Now.AddYears(100);
foreach (ListItem item in itemListchk.Items)
{
if (item.Selected)
{
Label1.Text = item.Text;
totalNumberItems+= int.Parse(item.Value);
Label1.Text +="Quantity \ "+ totalNumberItems.ToString();
}
}
Response.Cookies.Add(cookie);
// Label1.Text = "You have \ " + totalNumberItems.ToString() + "\ items in your cart ";
}
}