我在下面有这段代码,它为产品列表创建行和单元格。我想使用一个按钮来获取其他产品信息。基本上用户会搜索一些东西,它会显示有限的结果。当用户单击按钮时,它将调用一个方法来执行其他操作。
如何让该按钮将 ID 或其他内容传递给方法?
我尝试了.Click
但没有调用该方法。目前该方法只显示一个消息框。
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);
}
}
}