0

我有一个按钮,我想用它来生成软删除。使用带有 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() 方法。我应该在课堂上添加一些属性或其他东西吗?谢谢!

4

1 回答 1

0

命令参数值应在单引号内:

CommandArgument='<%# Eval("Product.Id") %>'
于 2017-09-16T15:47:03.500 回答