CommandArgument is returning null

965 views Asked by At

I have a Button that i want to generate a soft delete with. Used an OnCommand with an Eval CommandArgument.

  <asp:Button ID="Button2" ValidationGroup="Delete" runat="server" Text="Delete" OnCommand="Button2_Command" 
            CommandArgument=<%# Eval("Product.Id") %> />

But the CommandArgument keeps returning null at the method behind.

protected void Button2_Command(object sender, CommandEventArgs e)
    {
        var Id = e.CommandArgument.ToString();

        TransactionCode.DeletePurchase();
    }

The table that gets the Id is part of a .dll DataContext. It works just fine with everything but at this case it keeps returning me null. I also have a class in the .dll witch contains the DeletePurchase() method. Should i add some property or smth to the class? Thank you!

1

There are 1 answers

2
Abdullah Dibas On BEST ANSWER

The command argument value should be within single quotes :

CommandArgument='<%# Eval("Product.Id") %>'