【发布时间】:2017-09-16 15:37:19
【问题描述】:
我有一个按钮,我想用它来生成软删除。使用带有 Eval CommandArgument 的 OnCommand。
<asp:Button ID="Button2" ValidationGroup="Delete" runat="server" Text="Delete" OnCommand="Button2_Command"
CommandArgument=<%# Eval("Product.Id") %> />
但是 CommandArgument 在后面的方法中一直返回 null。
protected void Button2_Command(object sender, CommandEventArgs e)
{
var Id = e.CommandArgument.ToString();
TransactionCode.DeletePurchase();
}
获取 Id 的表是 .dll DataContext 的一部分。它适用于一切,但在这种情况下,它一直返回我为空。我在 .dll 中还有一个类,其中包含 DeletePurchase() 方法。我应该在课堂上添加一些属性或其他东西吗?谢谢!
【问题讨论】:
-
你是不是在函数中下了断点,看它是否正确获取传入的参数?
-
@Tim 是的,我在 Button2_Command() 事件的初始化处设置了一个断点,并且 var id 保持为空,因为命令参数仍然为空,但我检查了很多次 Eval 输入名称我想得到的表和属性。
标签: c# button commandargument