protected void SaveButton_Click(object sender, EventArgs e)
        {
            short quantity = AlwaysConvert.ToInt16(KitQuantity.Text);

            if (quantity > 0)
            {
                ProductVariant productVariant = null;
                if (_KitProduct.Product.ProductOptions.Count > 0)
                {
                    productVariant = ProductVariantDataSource.LoadForOptionList(_KitProduct.Product.Id, selectedOptions);
                }
                if (productVariant != null)
                {
                    _KitProduct.OptionList = productVariant.OptionList;
                }
                _KitProduct.Name         = DisplayName.Text;
                _KitProduct.Quantity     = quantity;
                _KitProduct.PriceModeId  = AlwaysConvert.ToByte(PriceMode.SelectedIndex);
                _KitProduct.Price        = AlwaysConvert.ToDecimal(Price.Text);
                _KitProduct.WeightModeId = AlwaysConvert.ToByte(WeightMode.SelectedIndex);
                _KitProduct.Weight       = AlwaysConvert.ToDecimal(Weight.Text);
                _KitProduct.IsSelected   = IsSelected.Checked;
                _KitProduct.Save();
            }
            Response.Redirect(string.Format("EditKit.aspx?CategoryId={0}&ProductId={1}", _CategoryId, _ProductId));
        }
 protected void FinishButton_Click(object sender, EventArgs e)
 {
     foreach (RepeaterItem ri in SelectedProductRepeater.Items)
     {
         HiddenField pid       = (HiddenField)ri.FindControl("PID");
         int         productId = AlwaysConvert.ToInt(pid.Value);
         Product     product   = ProductDataSource.Load(productId);
         if (product == null)
         {
             return;
         }
         if (!AllProductOptionsSelected(product, ri))
         {
             return;
         }
         TextBox KitQuantity = (TextBox)ri.FindControl("KitQuantity");
         short   quantity    = AlwaysConvert.ToInt16(KitQuantity.Text);
         if (quantity > 0)
         {
             ProductVariant productVariant = null;
             string         optionList     = string.Empty;
             if (product.ProductOptions.Count > 0)
             {
                 Dictionary <int, int> selectedOptions = GetSelectedOptions(ri.ItemIndex);
                 productVariant = ProductVariantDataSource.LoadForOptionList(productId, selectedOptions);
                 optionList     = ProductVariantDataSource.GetOptionList(productId, selectedOptions, true);
             }
             TextBox      NameFormat = (TextBox)ri.FindControl("NameFormat");
             DropDownList PriceMode  = (DropDownList)ri.FindControl("PriceMode");
             TextBox      Price      = (TextBox)ri.FindControl("Price");
             DropDownList WeightMode = (DropDownList)ri.FindControl("WeightMode");
             TextBox      Weight     = (TextBox)ri.FindControl("Weight");
             CheckBox     IsSelected = (CheckBox)ri.FindControl("IsSelected");
             KitProduct   kitProduct = new KitProduct();
             kitProduct.ProductId    = productId;
             kitProduct.KitComponent = _KitComponent;
             if (productVariant != null)
             {
                 kitProduct.OptionList = productVariant.OptionList;
             }
             kitProduct.Name     = NameFormat.Text;
             kitProduct.Quantity = quantity;
             ProductCalculator pcalc = ProductCalculator.LoadForProduct(productId, 1, optionList, string.Empty);
             kitProduct.PriceModeId = AlwaysConvert.ToByte(PriceMode.SelectedIndex);
             if (kitProduct.PriceMode == InheritanceMode.Inherit)
             {
                 kitProduct.Price = pcalc.Price;
             }
             else
             {
                 kitProduct.Price = AlwaysConvert.ToDecimal(Price.Text);
             }
             kitProduct.WeightModeId = AlwaysConvert.ToByte(WeightMode.SelectedIndex);
             if (kitProduct.WeightMode == InheritanceMode.Inherit)
             {
                 kitProduct.Weight = pcalc.Weight;
             }
             else
             {
                 kitProduct.Weight = AlwaysConvert.ToDecimal(Weight.Text);
             }
             kitProduct.IsSelected = IsSelected.Checked;
             kitProduct.Save();
         }
     }
     Response.Redirect(string.Format("EditKit.aspx?CategoryId={0}&ProductId={1}", _CategoryId, _ProductId));
 }