ASP.NET’s ObjectDataSource not calling SelectMethod in Insert mode

I’m going nuts… I have an ASP.NET page that I’ve added a DetailsView, being the good little programmer I am, I’m trying to grok the ASP.NET 2.0 way of databinding everything using ObjectDataSources (as I know how bad not being able to use proper data binding in ASP.NET 1.1 was for productivity)

But these productivity gains I’m hoping to see are not materializing, I’m trying to make the page create a new item, but I want the DetailsView to have a list of default values in each of the fields. Our Business Logic provides a CreateObject function that instantiates an object with system defaults. But apparenlty ObjectDataSource doesn’t support default values. Select never gets called with the Mode for the DetailsView is in Insert.  WHY MS?? WHY!!!

Investigating this it seems I’m not alone in my pain, but their solution is far from what I’m after… time to re-implement ASP.NET’s functionality (ASP.NET 1.1 pain all over again).

Update: I’ve come up with a simple solution!
Ok, this is solved fairly simply just by having DefaultMode="Edit" set on your DetailsView and having your DataSource with the following:  SelectMethod="GetOrCreate" UpdateMethod="AddOrUpdate".

The above functions can just be logic that looks at your input parameters and calls the appropriate method.

So in summary, as far as I’m concerned, never set DetailsView’s mode to Insert… it’s useless.

Advertisements
  1. How to set default value of a detailsView’s textbox in insert mode in an elegant way? | SeekPHP.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: