Modifying the "Update" object in ObjectDataSource?

  • Thread starter Thread starter JDC
  • Start date Start date
J

JDC

Hi all,

I'm using ObjectDataSource to select & update records. I have a
"RecordDetails" class which encapsulates the row I want to update, and
so it contains the fields I want to update and also the key fields that
limit the update.

The runtime automatically fills in the updatable fields in my object
from a GridView, but I need to set the limit fields before the
UpdateMethod is called.

I thought this would be the correct approach:

protected void ObjectDataSource1_Updating(object sender,
ObjectDataSourceMethodEventArgs e)
{
e.InputParameters["KeyField"] = someValueFromViewState;
}

But this throws an "OrderedDictionary is readonly and cannot be
modified." error.

I guess I'm overlooking something obvious; can anyone tell me what?!?

Cheers, J
 
If you're working with the ObjectDataSource using the
DataObjectTypeName property (passing objects in the CRUD methods) the
dictionaries passed to the inserting, updating and deleting events are
read only by design (bad design IMHO).

Take a look here for more information about limitations of the object
data source:

http://www.manuelabadia.com/blog/PermaLink,guid,32e83915-a503-403e-97c7-e20dcf2e0b7e.aspx

If you're interesting in overcoming this limitation, you can use the
free version of the ExtendedObjectDataSource (you can download it in
the purchase section):

http://www.manuelabadia.com/products

Hope it helps,
Manu

JDC ha escrito:
 
Wow, I'm really suprrised at this limitation. I can't believe I'm the
only person that doesn't want to display all my records in the grid,
and therefore needs to modify the DataObjectTypeName object with some
default values from the page, before it gets passed to the update
method.

How very annoying.

Thanks for the reply. I'll check out your comonent.

Cheers, J
 
Nice idea, but unfortunately the InputParameters are still read-only if
I specify the DataKeyNames.

Cheers, J
 
Back
Top