I have this code below that create rows and cells for a list of products. There is a button that I want to use to get additional product information. Basically the user will search for something and it will display limited results. When the user clicks on the button it will call a method that will do something else.
How do I get that button to pass and ID or something to a method?
I tried the .Click but did not work to call the method. Currently the method only displays a messagebox.
for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
{
// Create new row and add it to the table.
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
{
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
if (rowCtr == 1 && cellCtr == 1)
{
Image ProductImage = new Image();
ProductImage.Height = 75;
ProductImage.Width = 75;
tCell.RowSpan = 5;
tCell.Controls.Add(ProductImage);
tRow.Cells.Add(tCell);
}
if (rowCtr == 1 && cellCtr == 2)
{
tCell.Text = "Title: Title of Product";
tRow.Cells.Add(tCell);
}
if (rowCtr == 2 && cellCtr == 2)
{
tCell.Text = "Weight (lbs): 54";
tRow.Cells.Add(tCell);
}
if (rowCtr == 4 && cellCtr == 2)
{
Button getOfferButton = new Button();
getOfferButton.Width = 100;
getOfferButton.Text = "Get Offer";
getOfferButton.Click += new EventHandler(getOffer);
tCell.Controls.Add(getOfferButton);
tRow.Cells.Add(tCell);
}
}
}
I think you should be using
<asp:GridView />control instead of generating this with markup. One way to handle this is use theOnCommandevent and pass the ID as argumentand then the Handler