keyongtech


  keyongtech > dotnet.framework.aspnet.* > dotnet.framework.aspnet.webcontrols > 09/2006

 #1  
09-20-06, 08: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
 #2  
09-20-06, 03: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:
[url down]

Regards,
Manuel Abadia
[url down]

Urs Eichmann ha escrito:
[..]
 #3  
09-22-06, 10:11 PM
Urs Eichmann
Thanks Manu, this looks like an interesting solution. I will have a
look at it ASAP.
Urs

Manu schrieb:
[..]
Similar Threads
ObjectDataSource and GridView SortExpression with multiple columns problem

Hi, I've spent some time reading articles on gridview sorting when sort expression consists of multiple columns. I have to say that I'm as confused as ever. Could someone...

Hiding GridView Columns without Re-Firing ObjectDataSource Select

Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire...

GridView update using ObjectDataSource

Hi, I have a problem in which I'm using a GridView with an ObjectDataSource as a data source. The problem is that when I use the ObjectDataSource UPDATE routine I must have...

GridView ObjectDataSource hidden columns

Hi, I am painfully aware of the fact that with a GridView bound to an ObjectDataSource that if you have a hidden grid column (visible=false) then it does not post back that...

GridView - ObjectDataSource - Dynamic Columns

I can use a GridView and ObjectDataSource to bind my data using "Eval" expressions ... provided the GridView and related Column TemplateFields are defined as inline HTML. I...


All times are GMT. The time now is 04:23 AM. | Privacy Policy