private void FillPage() { try { if (!String.IsNullOrWhiteSpace(Request.QueryString["id"])) { int id = Convert.ToInt32(Request.QueryString["id"]); ProductsModel productsModel = new ProductsModel(); Product product = productsModel.GetProduct(id); lblPrice.Text = "Price per unit: <br/>R " + product.Price; lblTitle.Text = product.Name; lblDescription.Text = product.Description; lblItemNo.Text = id.ToString(); imgProduct.ImageUrl = "~/Images/Products/" + product.Image; int[] amount = Enumerable.Range(1, 20).ToArray(); ddlAmount.DataSource = amount; ddlAmount.AppendDataBoundItems = true; ddlAmount.DataBind(); } else { // error unhandled } } catch (Exception e) { String temp = e.ToString(); System.Console.WriteLine("Hello world " + temp); Response.Redirect("~/Pages/Errors/InternalServerErrorPage.aspx"); } }
private void FillPage(int id) { ProductsModel productsModel = new ProductsModel(); Product product = productsModel.GetProduct(id); txtDescription.Text = product.Description; txtName.Text = product.Name; txtPrice.Text = product.Price.ToString(); ddlImage.SelectedValue = product.Image; ddlType.SelectedValue = product.TypeId.ToString(); }
private void FillPage() { //Get selected product's type if (!String.IsNullOrWhiteSpace(Request.QueryString["id"])) { int id = Convert.ToInt32(Request.QueryString["id"]); ProductsModel productsModel = new ProductsModel(); Products products = productsModel.GetProduct(id); //Fill page with data lblPrice.Text = "€" + products.Price; lblTitle.Text = products.Name; lblDescription.Text = products.Description; lblItemNr.Text = id.ToString(); imgProduct.ImageUrl = "~/Images/Products/" + products.Image; //Fill Amount dropdownlist int[] amount = Enumerable.Range(1, 25).ToArray(); ddlAmount.DataSource = amount; ddlAmount.AppendDataBoundItems = true; ddlAmount.DataBind(); } }
private void CreateShopTable(IEnumerable <Cart> carts, out double subTotal) { subTotal = new double(); ProductsModel model = new ProductsModel(); foreach (Cart cart in carts) { Product product = model.GetProduct(cart.ProductID); //Create imagne buton ImageButton btnImage = new ImageButton { ImageUrl = string.Format("~/Images/Products/{0}", product.Image), PostBackUrl = string.Format("~/Pages/Product.aspx?id={0}", product.Id), }; //Create delete link LinkButton lnkDelete = new LinkButton { PostBackUrl = string.Format("~/Pages/ShoppingCart.aspx?productId={0}", cart.ID), Text = "Delete Item", ID = "del" + cart.ID }; //Add onclick event lnkDelete.Click += Delete_Item; //Create quantity dropdown list int[] amount = Enumerable.Range(1, 20).ToArray(); DropDownList ddlAmount = new DropDownList { DataSource = amount, AppendDataBoundItems = true, AutoPostBack = true, ID = cart.ID.ToString() }; ddlAmount.DataBind(); ddlAmount.SelectedValue = cart.Amount.ToString(); ddlAmount.SelectedIndexChanged += ddlAmount_SelectedIndexChanged; //Create html tables Table table = new Table { CssClass = "cartTable" }; TableRow a = new TableRow(); TableRow b = new TableRow(); //create 6 cells for a TableCell a1 = new TableCell { RowSpan = 2, Width = 50 }; TableCell a2 = new TableCell { Text = string.Format("<h4>{0}</h4><br/>{1}<br/>In Stock", product.Name, "Item No: " + product.Id), HorizontalAlign = HorizontalAlign.Left, Width = 350 }; TableCell a3 = new TableCell { Text = "Unit Price<hr/>" }; TableCell a4 = new TableCell { Text = "Quantity<hr/>" }; TableCell a5 = new TableCell { Text = "Item Total<hr/>" }; TableCell a6 = new TableCell { }; //create 6 cells for b TableCell b1 = new TableCell { }; TableCell b2 = new TableCell { Text = "R " + product.Price }; TableCell b3 = new TableCell { }; TableCell b4 = new TableCell { Text = "R " + Math.Round((cart.Amount * product.Price).Value, 2) }; //This line had to be ammended as it was throwing a error: cannot convert from double? to double. TableCell b5 = new TableCell { }; TableCell b6 = new TableCell { }; //set speical controls a1.Controls.Add(btnImage); a6.Controls.Add(lnkDelete); b3.Controls.Add(ddlAmount); //add cells to rows a.Cells.Add(a1); a.Cells.Add(a2); a.Cells.Add(a3); a.Cells.Add(a4); a.Cells.Add(a5); a.Cells.Add(a6); b.Cells.Add(b1); b.Cells.Add(b2); b.Cells.Add(b3); b.Cells.Add(b4); b.Cells.Add(b5); b.Cells.Add(b6); //Add rows to table table.Rows.Add(a); table.Rows.Add(b); //add table to pnlShoppingCart pnlShoppingCart.Controls.Add(table); //Add total amount item in cart to subtotal subTotal += (cart.Amount * product.Price).Value; //This line also had to be ammened like on line 95. } //Add curent users shopping cart to user specific session Session[User.Identity.GetUserId()] = carts; }