I have a GridView populated from an ObjectDataSource with two items in its DataKeyNames field. One is the primary key, ID, the other is a category field (the category field is used to add header rows to delineate categories).
Displaying works fine, but I'm trying to create a Delete action. The object's delete method only needs the ID field and in the ObjectDataSource even if I define the method as only needing an ID field, .net complains because it is looking for a method which has both the fields defined in DataKeyNames.
It works if I add a parameter for the category to the delete method, but it's annoying to have a parameter defined that isn't used for anything.
Can I configure the ObjectDataSource and GridView objects to have two values for DataKeyNames but specific which would should be passed to which methods?
The (simplified) definitions for the two objects are:
<asp:ObjectDataSource ID="ObjDS1" runat="server" SelectMethod="getAllItems"
TypeName="Items" DeleteMethod="deleteItem">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
<!-- This shouldn't be necessary: -->
<asp:Parameter Name="Category" Type="String" />
</DeleteParameters>
</asp:ObjectDataSource>
<asp:GridView ID="gvJItems" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,Category"
DataSourceID="ObjDS1">
<Columns>
<asp:BoundField DataField="ID" Visible="false" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="85%"/>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" Runat="server"
OnClientClick="return confirm('Are you sure you want to delete this?');"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>