deleting a row with Objectdatasource and gridview
I'm using Gridview with objectdatasource, I've selected select and delete method for objectdatasource, but i don't know how to set delete parameter (id) for objectdatasource. here is my code:
<apc:GridView ID="GridView1" runat="server" ApproveText="APPROVE" AutoGenerateColumns="False" CancelText="Canecl" CheckAllText="CHECK All" DataSourceID="ObjectDataSource1" DeleteAllText="Delete Selected Rows" DeleteButtonImageUrl="css/layout/site/tables/action4.gif" DeleteText="Delete" EditText="Edit" NewText="ADD NEW" SelectButtonImageUrl="css/layout/site/tables/action1.gif" SelectText="Select" ShowCheckBox="True" ShowDeleteAllButton="True" ShowDeleteButton="True" ShowEditButton="True" ShowNewButton="False" ShowSelectButton="True" Title="Table Template" UnCheckAllText="UNCHECK All" UpdateText="Update" DataKeyNames="Id" >
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
<asp:BoundField DataField="PhoneNumber" HeaderText="PhoneNumber" SortExpression="PhoneNumber" />
<asp:BoundField DataField="MobileNumber" HeaderText="MobileNumber" SortExpression="MobileNumber" />
<asp:BoundField DataField="CompanyPhone" HeaderText="CompanyPhone" SortExpression="CompanyPhone" />
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
</Columns>
i get ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Delete' that has parameters: id, original_Id. please help me. tanks.
In XML, Under ObjectDataSource1 change the value original_{0} to {0}
OR
change it to yourID name as it under Delete functionality XML code
EXAMPLE:
OldValuesParameterFormatString=original_{0} change to OldValuesParameterFormatString="myID"
ALSO,
<DeleteParameters>
<asp:Parameter Name="myID" Type="Int32" />
</DeleteParameters>
Thanks
It looks like you need to modify your delete method to accept an Id
parameter. I had a similar issue where I wasn't setting the DataKeyNames
property and once I did I got the same error as you. I resolved the issue by adding the Id
as a parameter to my function.
精彩评论