protected void Page_Load(object sender, EventArgs e) { prodcd = Request.QueryString["prodcd"].ToString(); var prod = new Product(); prod.GetProductByCode(prodcd); title.Text = prod.Name.ToString(); productCode.Text = prod.ProductCode.ToString(); brand.Text = prod.Brand.ToString(); //Get configurations Configuration config = new Configuration(); config.GetConfigurationByCode("xCurrencyCode"); price.Text = "$" + prod.Msrp.ToString() + " " + config.Value; LabelDescription.Text = prod.Description.ToString(); //If the unlimited quantity flag is set... if (Convert.ToBoolean(prod.IsQuantityUnlimited) == true) { quantity.Text = "Quantity Remaining: Unlimited"; } else { quantity.Text = "Quantity Remaining: " + prod.QuantityInStock.ToString(); } //Attempt to display image (if it is found) try { itemPic.ImageUrl = "~/Images/Product_Images/" + prodcd + ".jpg"; } catch (Exception) { itemPic.ImageUrl = ""; } //Fill gridview with available delivery types ProductDeliveryType pdt = new ProductDeliveryType(); List<ProductDeliveryType> pdtypes = pdt.GetAllProductDeliveryTypesByProdCode(prodcd); List<DeliveryType> deliveryTypes = new List<DeliveryType>(); foreach (ProductDeliveryType prodDelType in pdtypes) { DeliveryType dt = new DeliveryType(); dt.GetDeliveryTypeByID(prodDelType.DeliveryTypeID); deliveryTypes.Add(dt); } GridViewDeliveryTypes.DataSource = deliveryTypes; GridViewDeliveryTypes.DataBind(); //Don't show "Delivery Types" title if there are no delivery types listed if (deliveryTypes.Count == 0) { LabelDeliveryTypesTitle.Visible = false; } }
protected void DataListCheckout_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { var item = e.Item.DataItem as DataRowView; if (item != null) { //Set the checkbox value attribute var chk = e.Item.FindControl("CheckBoxUseUserAddress") as CheckBox; if (chk != null) { chk.InputAttributes.Add("value", item["Prodcd"].ToString()); } //Set the dropdownlist datasource DropDownList spDDL = e.Item.FindControl("dropStateProv") as DropDownList; StateProvince sp = new StateProvince(); List<StateProvince> states = sp.GetAllStatesProvinces(); spDDL.DataSource = states; spDDL.DataTextField = "Name"; spDDL.DataValueField = "StateProvinceID"; spDDL.DataBind(); //Get all ProductDeliveryType objects for this prodcd ProductDeliveryType pdt = new ProductDeliveryType(); List<ProductDeliveryType> pdtypes = pdt.GetAllProductDeliveryTypesByProdCode(item["Prodcd"].ToString()); //For each ProductDeliveryType, add its associated DeliveryType object to the list List<DeliveryType> dTypes = new List<DeliveryType>(); foreach (ProductDeliveryType pdtype in pdtypes) { DeliveryType delType = new DeliveryType(); delType.GetDeliveryTypeByID(pdtype.DeliveryTypeID); dTypes.Add(delType); } //Assign list of DeliveryType to data list DropDownList delTypesDDL = e.Item.FindControl("DropDownListDeliveryType") as DropDownList; delTypesDDL.DataSource = dTypes; delTypesDDL.DataTextField = "Name"; delTypesDDL.DataValueField = "DeliveryTypeID"; delTypesDDL.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { //Check if logged in if (Session["UserID"] == null) { //Set a session variable to indicate return to checkout after login Session.Add("ReturnToCheckout", true); Response.Redirect("~/Login.aspx"); } if (!IsPostBack) { List<Tuple<string, int>> list = new List<Tuple<string, int>>(); if (Session["cartList"] != null) { list = (List<Tuple<string, int>>)(Session["cartList"]); } else { Response.Redirect("~/Index.aspx"); } //Collection that will be bound to the checkout datalist List<CheckoutItem> coItems = new List<CheckoutItem>(); foreach (Tuple<string, int> item in list) { CheckoutItem coItem = new CheckoutItem(); coItem.Prodcd = item.Item1; coItem.Quantity = item.Item2; //Get product info Product prod = new Product(); prod.GetProductByCode(item.Item1); coItem.Name = prod.Name.ToString(); coItem.Msrp = prod.Msrp; //Get all product delivery types ProductDeliveryType pdt = new ProductDeliveryType(); List<ProductDeliveryType> pdtypes = pdt.GetAllProductDeliveryTypesByProdCode(prod.ProductCode.ToString()); foreach(ProductDeliveryType pdtype in pdtypes) { DeliveryType dt = new DeliveryType(); dt.GetDeliveryTypeByID(pdtype.DeliveryTypeID); coItem.DeliveryTypes.Add(dt); } //Add checkout item to datasource list coItems.Add(coItem); } //Bind to the datalist DataListCheckout.DataSource = coItems; DataListCheckout.DataBind(); } }