RSS 2.0 | Atom 1.0 | CDF

Search

Categories

Archive

Blogroll

Sign In

# Friday, December 16, 2005
Friday, December 16, 2005 2:21:53 PM (GMT Standard Time, UTC+00:00) ( Asp.Net )

i'm just experimenting with the gridview control, and i got stuck trying to delete an object with the auto-included delete button.  the delete method would get invoked properly, but the ID parameter was always zero, which means the int parameter was uninitialised.

my problem was that i didn't have the DataKeyNames property set in the Gridview. I just set it to 'ID' and it worked fine then.

Comments [17] | | # 
Tuesday, December 20, 2005 9:33:21 AM (GMT Standard Time, UTC+00:00)
Wow, thanks so much I had the same problem and your post saved me about an hour of searching.
Wednesday, December 21, 2005 12:26:03 AM (GMT Standard Time, UTC+00:00)
glad you found it helpful.
Tim Mackey
Tuesday, April 18, 2006 11:58:57 AM (GMT Daylight Time, UTC+01:00)
Thanks very much, Tim - I was also having this problem.
Chris Fulstow
Friday, August 18, 2006 6:11:51 PM (GMT Daylight Time, UTC+01:00)
Thank you! Same problem here. Really - really annoying.
Grateful Coder
Tuesday, October 03, 2006 10:46:08 PM (GMT Daylight Time, UTC+01:00)
Same here! Thanks for posting it!!
Ariel
Friday, October 06, 2006 1:18:16 PM (GMT Daylight Time, UTC+01:00)
THANK YOU VERY MUCH!!

I have spent several hours trying to understand why this didn't work. I works fine with Update!

// Kristian
Kristian
Wednesday, February 07, 2007 8:29:32 PM (GMT Standard Time, UTC+00:00)
Thanks, that really helped me :)
Joachim
Friday, February 09, 2007 7:37:34 PM (GMT Standard Time, UTC+00:00)
Same problems.

thanks
Camel
Thursday, April 05, 2007 12:29:46 AM (GMT Daylight Time, UTC+01:00)
Thanks. It is extremely usefull.
Sunday, April 15, 2007 9:15:15 PM (GMT Daylight Time, UTC+01:00)
The DataKeyNames is neccesary also when the delete method take the whole object has parameters.

Thanks
Pbl
Thursday, January 24, 2008 12:05:42 AM (GMT Standard Time, UTC+00:00)
Thank you. I spent hours trying to figure this out.
Monday, July 07, 2008 2:21:12 PM (GMT Daylight Time, UTC+01:00)
What a HELP!!

Thankz, I will forward you post!
Wednesday, November 05, 2008 4:25:24 AM (GMT Standard Time, UTC+00:00)
My delete method requires 2 more parameters, yet they are being passed as NULL byt the objectdatasource to my delete method. I've checked the deleteparameters and they look ok. I've been pulling my hair out for a few days over this - can anyone help?
Holdfast
Friday, November 07, 2008 7:19:17 PM (GMT Standard Time, UTC+00:00)
I also spent several hours trying to figure this out. So glad I found your blog.

THANK YOU!
Will Hutton
Saturday, June 20, 2009 12:58:18 PM (GMT Daylight Time, UTC+01:00)
I have exactly the same problem and it's solved

thanks
Thursday, July 02, 2009 9:50:11 AM (GMT Daylight Time, UTC+01:00)
So after 4 years, people are still searching on this issue. Great post Tim - short and sweet and an apparent life saver after so long. I'd like to extend it a bit for others:

1. Microsoft's documentation on this is sorely lacking, so no, it's not you ;)

2. Although the DataSource wizard for ObjectDataSource doesn't show you the params for INSERT, UPDATE, and DELETE, you must still set them (at least in VS2008). Go to the properties window of your ObjectDataSource control and look at the data section. You'll find a property for each type (for example, for DELETE you'll see DeleteParameters) and it will be a collection. Expand the collection and it brings up a wizard to help you define your parameters. This is essential; why this isn't part of the main wizard (except for SELECT), I couldn't tell you. Establish your params here and you won't receive nulls.

3. For those programmatically creating their data: If you are using an ObjectDataSource which returns a DataSource you've constructed (ie, not from a DB), then be sure to set the PrimaryKey property of each table in the datasource. Since you may have more than one key, here's a snippet (VB.net)

'Create your table
dim dtTable as New DataTable()
'...put some data in it...

'Set primary key
Dim dcKey(1) As DataColumn
dcKey(1) = dtTable.Columns.Item(FIELD_FEATUREKEY)
dtTable.PrimaryKey = dcKey

The sneaky thing about the PrimaryKey property, is that it expects an array - not a column (in case your table has multiple keys).

Tie it all together and your DELETE and other methods should work fine.

Karim Sultan
Thursday, March 31, 2011 1:40:39 PM (GMT Daylight Time, UTC+01:00)
Thank you!
Olive Oil
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview