//the rest of the rest of the code go in the ddlTypes_SelectedIndexChanged protected void ddlTypes_SelectedIndexChanged(object sender, EventArgs e) { //Get list of products by type Prod_Model productModel = new Prod_Model(); List <Product> products = productModel.GetAlloftheProductsByType(Int32.Parse(ddlTypes.SelectedValue)); //Make sure product exist in DB if (products != null) { //Create new Panel foreach (Product product in products) { Panel productPanel = new Panel(); ImageButton imageButton = new ImageButton(); Label lblName = new Label(); Label lblPrice = new Label(); } } }
/// <summary> /// /////////////////////////////////////////////////////////////////////////////////////// /// </summary> private void SetupPage() { //to show all products in the database.. Prod_Model prod_model = new Prod_Model(); List <Product> products = prod_model.GetAlloftheProducts(); //to make sure the products are in the database as before if (products != null) { //to create a new panel area with 2 labels for price and descrition and an image foreach (Product product in products) { Panel prod_Panel = new Panel(); ImageButton img_Button = new ImageButton(); Label lblName = new Label(); Label lblprice = new Label(); // properties for childcontrols img_Button.ImageUrl = "~/Images/ProductImg/" + product.Image; img_Button.CssClass = "prodImg"; img_Button.PostBackUrl = "~/Pages/Item.aspx?id=" + product.Id; lblName.Text = product.Name; lblName.CssClass = "prodNme"; lblprice.Text = "£" + product.Price; lblprice.CssClass = "prodPrice"; //panel child controls prod_Panel.Controls.Add(img_Button); prod_Panel.Controls.Add(new Literal { Text = "<br/>" }); prod_Panel.Controls.Add(lblName); prod_Panel.Controls.Add(new Literal { Text = "<br/>" }); prod_Panel.Controls.Add(lblprice); //to make panels dynamic panlProds.Controls.Add(prod_Panel); } } else { //in the event no product is found panlProds.Controls.Add(new Literal { Text = "No products are available" }); } }
private void SetPage(int id) { //to get the selected product from the database Prod_Model prod_model = new Prod_Model(); Product product = prod_model.Get_Prod(id); // fill all the textboxes txtDescription.Text = product.Description; txtName.Text = product.Name; txtPrice.Text = product.Price.ToString(); // to set the values of the dropdown list ddlImage.SelectedValue = product.Image; ddlTypes.SelectedValue = product.TypeId.ToString(); }
protected void btnSubmit_Click(object sender, EventArgs e) { Prod_Model prod_model = new Prod_Model(); Product product = CreatePrpduct(); //to check if url contains an id if (!String.IsNullOrWhiteSpace(Request.QueryString["id"])) { //when an ID exists-- update certain row int id = Convert.ToInt32(Request.QueryString["id"]); lblResult.Text = prod_model.UpdateProduct(id, product); } else { //here id does noot exist.. create a new row lblResult.Text = prod_model.InsertProduct(product); } }
private void setPage() { //get the current product details if (!string.IsNullOrWhiteSpace(Request.QueryString["id"])) { int id = Convert.ToInt32(Request.QueryString["id"]); Prod_Model prod_item = new Prod_Model(); Product product = prod_item.Get_Prod(id); //setup cuurent page lblPrice.Text = "Unit price: <br/>£ " + product.Price; lblTitle.Text = product.Name; lblDesc.Text = product.Description; lblIDno.Text = product.Id.ToString(); imgProd.ImageUrl = "~/Images/ProductImg/" + product.Image; //to fill the amout ddl box with amt of nos. from 1-20 int[] noofitems = Enumerable.Range(1, 20).ToArray(); ddlAmt.DataSource = noofitems; ddlAmt.AppendDataBoundItems = true; ddlAmt.DataBind(); } }
private void OrganiseCartWindow(List <Cart> orderList, out double AmtTotal) { AmtTotal = new Double(); Prod_Model type = new Prod_Model(); foreach (Cart cart in orderList) { //get databse data o fill page Product product = type.Get_Prod(cart.ProductID); //for the item image ImageButton buttonImage = new ImageButton { ImageUrl = string.Format("~/Images/ProductImg/{0}", product.Image), PostBackUrl = string.Format("~/Pages/Item.aspx?id={0}", product.Id) }; // delete cart items LinkButton linkDelete = new LinkButton { PostBackUrl = string.Format("~/Pages/Trolley.aspx?productId={0}", cart.ID), Text = "Remove Item", ID = "no" + cart.ID, }; //onclick events linkDelete.Click += Remove_Product; //Make a dropdownlist //list from numbers 1-20 int[] itemamount = Enumerable.Range(1, 20).ToArray(); DropDownList dropdownlistAmnt = new DropDownList { DataSource = itemamount, AppendDataBoundItems = true, AutoPostBack = true, ID = cart.ID.ToString() }; dropdownlistAmnt.DataBind(); dropdownlistAmnt.SelectedValue = cart.Amount.ToString(); dropdownlistAmnt.SelectedIndexChanged += dropdownlistAmnt_SelectdIndxChang; //populate cart details table with data //this is for table with 2 rows.. called lane Table datawindow = new Table { CssClass = "CartWindow" }; TableRow laneA = new TableRow(); TableRow laneB = new TableRow(); //create a six celled row for the first row.. called pane TableCell pane1 = new TableCell { RowSpan = 2, Width = 51 }; TableCell pane2 = new TableCell { Text = string.Format("<h4>{0}</h4><br />{1}<br/>Item In Stock", product.Name, "Product No:" + product.Id), HorizontalAlign = HorizontalAlign.Left, Width = 351, }; TableCell pane3 = new TableCell { Text = "Price per Unit<hr/>" }; TableCell pane4 = new TableCell { Text = "Quantity<hr/>" }; TableCell pane5 = new TableCell { Text = "Item *Total<hr/>" }; TableCell pane6 = new TableCell(); //to create a six celled row for the second row.. called panea..z TableCell panea1 = new TableCell(); TableCell paneb2 = new TableCell { Text = "£ " + product.Price }; TableCell panec3 = new TableCell(); TableCell paned4 = new TableCell { Text = "£ " + Math.Round((cart.Amount * (double)product.Price)) }; TableCell panee5 = new TableCell(); TableCell panef6 = new TableCell(); //Set customized controls pane1.Controls.Add(buttonImage); pane6.Controls.Add(linkDelete); panec3.Controls.Add(dropdownlistAmnt); //make some rows & cells to table laneA.Cells.Add(pane1); laneA.Cells.Add(pane2); laneA.Cells.Add(pane3); laneA.Cells.Add(pane4); laneA.Cells.Add(pane5); laneA.Cells.Add(pane6); laneB.Cells.Add(panea1); laneB.Cells.Add(paneb2); laneB.Cells.Add(panec3); laneB.Cells.Add(paned4); laneB.Cells.Add(panee5); laneB.Cells.Add(panef6); //create rows datawindow.Rows.Add(laneA); datawindow.Rows.Add(laneB); //display created table in panel paneltrolley.Controls.Add(datawindow); //Add total of current purchased item to subtotal AmtTotal += (cart.Amount * (double)product.Price); } //Add the utems to session Session[User.Identity.GetUserId()] = orderList; }