Esempio n. 1
0
        /// <summary>
        /// Function to control user clicking on a button on the page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CommandClicked(object sender, RepeaterCommandEventArgs e)
        {
            // Check for update button
            if (e.CommandName == CMD_UPDATE)
            {
                TextBox txt;
                int     qty;
                int     index;

                // Go through each item on the page
                for (int i = 0, j = cart.Items.Count; i < j; i++)
                {
                    // lookup the control
                    txt = (TextBox)cart.Items[i].FindControl(ID_TXT);

                    try{
                        qty   = int.Parse(txt.Text);
                        index = cart.CurrentPageIndex * cart.PageSize + i;

                        // If the new qty is zero, remove the item from the cart
                        if (qty <= 0)
                        {
                            myCart.RemoveAt(index);
                        }
                        // Update the item with the new quantity
                        else
                        {
                            myCart[index].Quantity = qty;
                        }
                    }
                    catch {}
                }
            }
            else
            {
                // otherwise the command is to remove the an item
                myCart.Remove((string)e.CommandArgument);
            }

            // Refresh the contents of the cart page
            Refresh();

            // Update the page count if required
            int pageCount = (myCart.Count - 1) / cart.PageSize;

            cart.SetPage(Math.Min(cart.CurrentPageIndex, pageCount));
        }