没有找到关于此的具体答案,所以它就来了...我正在foreach
循环中创建HTML表,在该循环中,每次为其对应顺序创建行。我有两个按钮,如下面的代码所示:
private void CreateOrderTable(List<Order> orders)
{
OrderModel model = new OrderModel();
foreach (Order order in orders)
{
Order orderN = new Order();
//Create HTML Table
Table table = new Table { CssClass = "cartTable" };
TableRow a = new TableRow();
TableRow b = new TableRow();
//Crear cells for row a
TableCell a1 = new TableCell { RowSpan = 2, Width = 50 };
TableCell a2 = new TableCell
{
Text = string.Format(order.OrderID.ToString()),
HorizontalAlign = HorizontalAlign.Left,
Width = 350
};
TableCell a3 = new TableCell { Text = "Monto:<hr/>" };
TableCell a4 = new TableCell { Text = "Restaurante:<hr/>" };
TableCell a5 = new TableCell { Text = "Estado<hr/>" };
TableCell a6 = new TableCell { Text = "Tarjeta<hr/>" };
TableCell a7 = new TableCell { Text = "<asp:LinkButton OnClick=\"AcceptPayment\" runat=\"server\" class=\"myButtonGreen\">Aceptar Pago</asp:LinkButton>" };
TableCell a8 = new TableCell { Text = "<asp:LinkButton OnClick=\"RejectOrder\" runat=\"server\" class=\"myButtonRed\">Anular Orden</asp:LinkButton>" };
//Create cells for row b
TableCell b1 = new TableCell { };
TableCell b2 = new TableCell { Text = order.Amount.ToString() };
TableCell b3 = new TableCell { Text = order.Restaurante.ToString() };
TableCell b4 = new TableCell { Text = order.OrderState.ToString() };
TableCell b5 = new TableCell { Text = order.CardNumber + " " + order.CardDate };
TableCell b6 = new TableCell { };
//Add cells to columns
a.Cells.Add(a1);
a.Cells.Add(a2);
a.Cells.Add(a3);
a.Cells.Add(a4);
a.Cells.Add(a5);
a.Cells.Add(a6);
a.Cells.Add(a7);
a.Cells.Add(a8);
b.Cells.Add(b1);
b.Cells.Add(b2);
b.Cells.Add(b3);
b.Cells.Add(b4);
b.Cells.Add(b5);
b.Cells.Add(b6);
//Add rows to table
table.Rows.Add(a);
table.Rows.Add(b);
//Add table to panel
pnlShoppingCart.Controls.Add(table);
}
}
protected void AcceptPayment(object sender, EventArgs e)
{
}
protected void RejectOrder(object sender, EventArgs e)
{
}
和我调用的OnClick
事件没有被访问,因为我在VS上放置了调试标记。
为什么会这样?
此外,我如何将int传递给事件?
答案 0 :(得分:1)
您可能应该创建实际的LinkButton
(或LinkButton
)对象,而不是创建HtmlAnchor
的字符串,然后将它们添加到表单元格的Controls集合中。
赞:
var lb = new LinkButton();
lb.Text = "Aceptar Pago";
lb.CssClass = "myButtonGreen";
lb.Click += AcceptPayment;
a7.Controls.Add(lb);