Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 81405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:27:17+00:00 2026-05-10T21:27:17+00:00

I have a GridView populated from an ObjectDataSource with two items in its DataKeyNames

  • 0

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> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:27:18+00:00Added an answer on May 10, 2026 at 9:27 pm

    All of the DataKey values will always be passed to the Delete method because the fields named by DataKeyNames are intended to be the field or fields that uniquely identify that item in the GridView. They’re often used for more than that to easily maintain extra fields on a per-row basis in ViewState as you are here, but doing so has the side-effect that you’re seeing with the ObjectDataSource methods.

    To answer your original question, no, you can’t have Category be in DataKeyNames without having it be passed to the Delete method. You could maintain the value in ViewState by putting the value in a hidden input in your Template Column, though. It would be more work to get that value out than to ignore the parameter to the Delete method, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I suggest you create at least two types website, one… May 11, 2026 at 5:52 pm
  • Editorial Team
    Editorial Team added an answer I am running the code on a click event. The… May 11, 2026 at 5:52 pm
  • Editorial Team
    Editorial Team added an answer Fubu MVC perhaps? May 11, 2026 at 5:52 pm

Related Questions

I'm trying out Linq for the first time and having a bit of difficult
(ASP.net 3.5, C#, SQL Express 2008) I want to have a Web Form, where
I have a dropdown list that stores name/value pairs. The dropdown appears in each
I want to use the GridView mode of a ListView to display a set

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.