private void LoadCustomOptions() { var customOptions = new List <CustomOption>(); foreach (RepeaterItem item in rCustomOptions.Items) { var customOption = new CustomOption { CustomOptionsId = ((HiddenField)(item.FindControl("hfId"))).Value.TryParseInt(), ProductId = ((HiddenField)(item.FindControl("hfProductId"))).Value.TryParseInt() }; if (string.IsNullOrEmpty(((TextBox)(item.FindControl("txtTitle"))).Text)) { _valid = false; } int i; if (!int.TryParse(((TextBox)(item.FindControl("txtSortOrder"))).Text, out i)) { _valid = false; } customOption.Title = ((TextBox)(item.FindControl("txtTitle"))).Text; customOption.InputType = (CustomOptionInputType)((((DropDownList)(item.FindControl("ddlInputType"))).SelectedValue.TryParseInt())); customOption.IsRequired = ((CheckBox)(item.FindControl("cbIsRequired"))).Checked; try { customOption.SortOrder = Convert.ToInt32(((TextBox)(item.FindControl("txtSortOrder"))).Text); } catch (Exception) { customOption.SetFieldToNull(CustomOptionField.SortOrder); } customOption.Options = new List <OptionItem>(); if (customOption.InputType == CustomOptionInputType.CheckBox) { var opt = new OptionItem { Title = " " }; try { opt.PriceBc = Convert.ToDecimal(((TextBox)(item.FindControl("txtPrice"))).Text); } catch (Exception) { opt.SetFieldToNull(OptionField.PriceBc); _valid = false; } opt.PriceType = OptionPriceType.Fixed; if (Enum.IsDefined(typeof(OptionPriceType), ((DropDownList)(item.FindControl("ddlPriceType"))).SelectedValue)) { opt.PriceType = (OptionPriceType)Enum.Parse(typeof(OptionPriceType), ((DropDownList)(item.FindControl("ddlPriceType"))).SelectedValue, true); } customOption.Options.Add(opt); } else { foreach (GridViewRow row in ((GridView)(item.FindControl("grid"))).Rows) { var opt = new OptionItem { OptionId = ((Label)(row.Cells[0].FindControl("lId"))).Text.TryParseInt() }; if (string.IsNullOrEmpty(((TextBox)(row.Cells[1].FindControl("txtTitle"))).Text) && !(customOption.InputType == CustomOptionInputType.CheckBox || customOption.InputType == CustomOptionInputType.TextBoxMultiLine || customOption.InputType == CustomOptionInputType.TextBoxSingleLine)) { _valid = false; } opt.Title = ((TextBox)(row.Cells[1].FindControl("txtTitle"))).Text; try { opt.PriceBc = Convert.ToDecimal(((TextBox)(row.Cells[2].FindControl("txtPriceBC"))).Text); } catch (Exception) { opt.SetFieldToNull(OptionField.PriceBc); _valid = false; } opt.PriceType = OptionPriceType.Fixed; if (Enum.IsDefined(typeof(OptionPriceType), ((DropDownList)(row.Cells[3].FindControl("ddlPriceType"))).SelectedValue)) { opt.PriceType = (OptionPriceType)Enum.Parse(typeof(OptionPriceType), ((DropDownList)(row.Cells[3].FindControl("ddlPriceType"))).SelectedValue, true); } try { opt.SortOrder = int.Parse(((TextBox)(row.Cells[4].FindControl("txtSortOrder"))).Text); } catch (Exception) { opt.SetFieldToNull(OptionField.SortOrder); _valid = false; } customOption.Options.Add(opt); } } customOptions.Add(customOption); } _customOptions = customOptions; }