I have just commented this as side-note but maybe it's your issue because you mention that "it doesn't seem to be a valid argument, though I can't think why not... Unless I have to explicitly convert it into a int".
If ID
is an int
you should use int.Parse(celltext)
, othwerwise the database gets the wrong type since AddWithValue
needs to infer the type from the value.
So use:
command.Parameters.AddWithValue("@ID", int.Parse(GridView1.Rows[row].Cells[0].Text));
Apart from that, you haven't added the event handler GridView1_RowCommand
.
<asp:GridView ID="GridView1" OnRowCommand="GridView1_RowCommand" runat="server" AutoGenerateColumns="False" DataKeyNames="SysInvoiceID" DataSourceID="SqlDataSource1">
....
and you are also not setting the CommandArgument
to the index of the row. I would use a different approach anyway if you need the row-index. Use a templatefield and a control, for example a Button
. Then use it's NamingContainer
property to get the reference to the 'GridViewRow`, here is an example: Get Row Index on Asp.net Rowcommand event