Home All Groups Group Topic Archive Search About

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

Author
20 Sep 2006 7:23 AM
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

Author
20 Sep 2006 2:09 PM
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:

Show quoteHide quote
> 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
Author
22 Sep 2006 9:11 PM
Urs Eichmann
Thanks Manu, this looks like an interesting solution. I will have a
look at it ASAP.
Urs

Manu schrieb:

Show quoteHide quote
> 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:
>
> > 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