|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ASP.NET 2.0 / GridView / ObjectDataSource / Update / Missing ColumnsMy 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 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 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
Control of a map where the user can click and drag to select an area...
OnDocumentReady with Treeview HTC (in a popup) The parameter is not correct from SqlDataAdapter control Failed validation doesn't stop page from posting back Binding Typed datasets to grid controls in designer A Repeater Question. How to keep state of treeview control gridview with hyperlinkfield How to update CheckBoxList inside a DetailsView? No Render on Treeview event |
|||||||||||||||||||||||