D Green

D Green

  • NA
  • 8
  • 13.4k

How to retrieve data from a panel

Jan 12 2015 5:41 PM

I created a panel using dynamic controls. Within the foreach statement, a few rows of label: Name and Price with a Update button for each row are created.   When the user clicks on the Update button for a particular row, how do i get the correct row to be updated and get the values from the panel per that row into the Update method? 

Thank you for your assistance in advance.


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);


   //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);


   //Add dynamic Panels to static Parent panel
   pnlCart.Controls.Add(cartPanel);
}


 protected void lkbUpdate_Click(object sender, EventArgs e)
{
  ....code here...
}

 


Answers (1)