I have an issue where a Gridview delete is not working correctly. It seems to have something to do with the DeleteCommand and the DeleteParameters. For example, if I give a static value to the DeleteCommand, rather than use the DeleteParameter, the gridview does delete the record with the value I specify statically. Code is below.
<asp:GridView ID="testGridView" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="Test_ID"
DataSourceID="dsourceTest">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="Test_ID" HeaderText="Test_ID"
InsertVisible="False" ReadOnly="True" SortExpression="Test_ID" />
...MORE COLUMNS HERE...
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsourceTest" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="SELECT Test_ID, C2, C3, C4, C5, C6, COALESCE(C7, '') AS C7, C8 FROM TestTable1"
DeleteCommand="DELETE FROM [TestTable1] WHERE [Test_ID] = @Test_ID">
<DeleteParameters>
<asp:Parameter Name="Test_ID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
So with the DeleteCommand above as it is, the Delete won't work. But if I change it to DeleteCommand="DELETE FROM [TestTable1] WHERE [Test_ID] = 27"
for example, and I hit a Delete button in the Gridview, it would delete the record with the Test_ID of 27.