protected void OptionChoicesGrid_RowDeleting(object sender, GridViewDeleteEventArgs e) { int optionId = (int)OptionChoicesGrid.DataKeys[e.RowIndex].Value; //FIND THE OPTION IList <OptionChoice> options = _Option.Choices; int index = -1; int i = 0; while ((i < options.Count) && (index < 0)) { if (options[i].Id == optionId) { index = i; } i++; } if (index >= 0) { options.DeleteAt(index); //REBUILD VARIANT GRID FOR THIS PRODUCT int productId = AbleCommerce.Code.PageHelper.GetProductId(); if (productId > 0) { ProductVariantManager.ScrubVariantGrid(productId, optionId); } BindChoicesGrid(); } }
/// <summary> /// Deletes this OptionChoice object from database /// </summary> /// <returns><b>true</b> if delete successful, <b>false</b> otherwise.</returns> public bool Delete() { //STORE DATA NECESSARY TO SCRUB VARIANT GRID AFTER DELETE int deletedChoiceId = this.OptionChoiceId; List <int> associatedProducts = new List <int>(); foreach (ProductOption po in this.Option.ProductOptions) { associatedProducts.Add(po.ProductId); } //NOW CALL THE DELETE if (BaseDelete()) { //DELETE SUCCEEDED, SCRUB THE VARIANT GRID foreach (int productId in associatedProducts) { ProductVariantManager.ScrubVariantGrid(productId, deletedChoiceId); } //RETURN SUCCESS return(true); } //BASE DELETE FAILED return(false); }