ASP.NET 2.0 / GridView / ObjectDataSource / Update / Missing Columns

U

Urs Eichmann

Hello,
My GridView is bound to an ObjectDataSource for select / update /
insert. Everything basically works as expected.

However, in the following scenario there is a problem:
My entity "Customer" consisits of three properties, "id", "Name" and
"City". These are all being displayed in the GridView.

Now I add a fourth Property "State" to the custom entity, which is
being used elsewhere. It is not being displayed in the grid.

Now, every time the "Customer" entity is being updated from my
GridView, the State property is being reset to the default value! Only
if I add a bound column for the "State" property to the grid (could be
invisible), the value is actually left as it was.

This is very dangerous and means, that if somebody adds a new Property
to the Customer entity, she/he has to remember to update all the
GridViews in the entiry application with the new property. This can't
be the ultimate solution?!

How can I prevent this behaviour?

Thanks for any help,
Urs
 
M

Manu

Urs,

this is by design when you are using the ObjectDataSource with custom
object as parameters for the update method.

When the update operation takes place, the ObjectDataSource
instantiates a new object (a Customer in your case), and then sets its
properties with the values from the control using the data source. In
your sample, the GridView passes a Customer instance with the Id, Name
and City properties set, but the missing properties are not set and
have the default values. When the update completes you have lost the
proper values of the properties that are not shown!

Take a look at the ExtendedObjectDataSource that can help you in this
scenario:
http://www.manuelabadia.com/livedemo/extendedobjectdatasource/DataObjectTypeControl.aspx

Regards,
Manuel Abadia
http://www.manuelabadia.com

Urs Eichmann ha escrito:
 
U

Urs Eichmann

Thanks Manu, this looks like an interesting solution. I will have a
look at it ASAP.
Urs
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top