0

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!

  • Did you put a breakpoint in the function to see if it is getting the parameters passed in correctly? – Tim Sep 16 '17 at 15:41
  • @Tim yes i put a breakpoint at the Initialization of the Button2_Command() Event and the var id remains the null cause the command arguments still is null, but i checked so many time the Eval putting the name of the table and the property i want to get. – user3636966 Sep 16 '17 at 15:46

1 Answers1

0

The command argument value should be within single quotes :

CommandArgument='<%# Eval("Product.Id") %>'
Abdullah Dibas
  • 1,499
  • 1
  • 9
  • 13
  • HI, thank you for the observation there, it missed me but i still got the problem. `var Id = e.CommandArgument.ToString();` still remains null. If i want to get data from that table from the Eval should the tables be connected with a single foreing key, or should i add a field in the table Product as a nullable transaction code for the Eval to work? – user3636966 Sep 16 '17 at 16:00
  • I fixed the problem, it was a contextual one. Your answer helped me alot, thank you. – user3636966 Sep 17 '17 at 10:40