Modifying the "Update" object in ObjectDataSource?

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
 
M

Manu

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:
 
J

JDC

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
 
J

JDC

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

Cheers, J
 
Joined
Oct 23, 2007
Messages
1
Reaction score
0
What you need to do is to retrieve the object from the parameters, and feed it manually, e.g.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top