foreach (Cart cartlist in cart) { int crtId = cartlist.ID; Panel cartPanel = new Panel(); Label lblName = new Label(); lblName.Text = product.Name; lblName.CssClass = "atcName"; Label lblPrice = new Label { Text = String.Format("{0:c}", product.Price), CssClass = "atcPrice" }; totalCounter++; //totalCounter = totalCounter + 1 Button lkbUpdate = new Button { CssClass = "lkbUpdate", Text = "Update" };lkbUpdate.Click += new EventHandler(lkbUpdate_Click); LinkButton lkbRemove = new LinkButton { CssClass = "lkbRemove", Text = "Remove", };lkbRemove.Click += new EventHandler(lkbRemove_Click);
//Add child controls to Panel cartPanel.Controls.Add(lblName); cartPanel.Controls.Add(new Literal { Text = "<br />" }); cartPanel.Controls.Add(lblPrice); cartPanel.Controls.Add(new Literal { Text = "<br />" }); cartPanel.Controls.Add(lkbUpdate); cartPanel.Controls.Add(lkbRemove); //Add dynamic Panels to static Parent panel pnlCart.Controls.Add(cartPanel); } protected void lkbRemove_Click(object sender, EventArgs e) { ....code here... }