Пример #1
0
    protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        int         rowsCount = grid.Rows.Count;
        GridViewRow gridRow;
        TextBox     quantityTextBox;

        int  quantity;
        bool success = true;

        for (int i = 0; i < rowsCount; i++)
        {
            gridRow                  = grid.Rows[i];
            strProductID             = grid.DataKeys[i]["ProductID"].ToString();
            strProductSellerDetailID = grid.DataKeys[i]["ProductSellerDetailID"].ToString();
            quantityTextBox          = (TextBox)gridRow.FindControl("txtQuantity");

            if (Int32.TryParse(quantityTextBox.Text, out quantity) && Int32.TryParse(strProductID, out intProductID) && Int32.TryParse(strProductSellerDetailID, out intProductSellerDetailID))
            {
                try
                {
                    using (ShoppingCartAccess cart = new ShoppingCartAccess())
                    {
                        success = success && cart.ShoppingCart_UpdateItem(intProductID, intProductSellerDetailID, quantity);
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    lblSystemMessage.Text = "Error:" + ex.Message;
                }
            }
            else
            {
                success = false;
            }
            lblStatus.Text = success ?
                             "<br />Your shopping cart was successfully updated!<br />" :
                             "<br />Some quantity updates failed! Please verify your cart!<br />";
        }
        // Repopulate the control
        PopulateControls();
    }