|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GridView w/ ObjectDataSource w/ Business object layerCurrent situation: -------------------- 1- layered architecture: presentation / Business Object / Providers 2- Business Object binding class feature create, delete, update, select methods to be consummed by the ObjectDataSource IMPORTANT: these methods expect a Business object instance, NOT parameters i.e. <ComponentModel.DataObjectMethod(DataObjectMethodType.Insert)> sub create(byval bo as BO) bo.create() end sub 3- Using ObjectDataSource incl. DataObjectTypeName="some.class.name" ... insertMethod="create" ... 4- Currently working on a custom GridView ("...class CustomGridView inherits GridView...") which includes a spreadsheet-like interface allowing new row to be created within the GridView itself Problem ---------- - After I intercept the RowCommand event and perform my insertion by calling the ObjectDataSource "insert()" method, I receive the following exception: "ObjectDataSource 'ObjectDataSource1' has no values to insert. Check that the 'values' dictionary contains values" The reason for this problem comes from the fact that the Business Object is NOT instantiated (or so I think). It appears the formView and GridView controls performs these instantiation steps (when specifying the "DataObjectTypeName" attribute) when using the update and delete built-in functionality. Can someone assist me in finding out how to instantiate the business object inside the gridView_RowCommand function in order to perform the insertion? (Reflection maybe??) Thank you You don't have to instantiate the business object yourself. It will be
instantiated by ObjectDataSource infrastructure. When you work with a control like the GridView, you don't have to call the methods from the ObjectDataSource. You should get the underlying view and call the ObjectDataSourceView methods. The exception you're getting is becouse the ObjectDataSource Insert method calls the ObjectDataSourceView Insert method with a null value, so it doesn't have anything to insert. You should call the ObjectDataSource Insert method with a dictionary containing the parameters needed to populate your object. For example, if you are working with products and you want to insert a product that has id, name, description and price, the dictionary you're passing to the Insert method needs to have some of this entries. Then the ODS will use them to create an instance of your product class and set all the properties that have the same name as the entries in the dictionary with their respective values. If you're a bit lost you can check my posts about the ODS and the new data source controls (specially parameter merging in part 3 on the ODS and DataSourceView and part 2 & 3 of the new data source controls). Post about the ODS: Part 1 - The basics - http://www.manuelabadia.com/blog/PermaLink,guid,c72852ae-1fdd-4934-a715-f565ceaf21cc.aspx Part 2 - Paging, Sorting, Parameters and Events - http://www.manuelabadia.com/blog/PermaLink,guid,f002752d-1258-475d-9ec0-eee3bd98d0a4.aspx Part 3 - Optimistic Concurrency, parameter merging, caching and design time attributes - http://www.manuelabadia.com/blog/PermaLink,guid,eaa3eed8-f997-43c4-8c30-78c2f72d0c86.aspx Part 4 - Limitations, problems and possible solutions - http://www.manuelabadia.com/blog/PermaLink,guid,32e83915-a503-403e-97c7-e20dcf2e0b7e.aspx Post about the new data source controls: Part 1 - http://www.manuelabadia.com/blog/PermaLink,guid,678ed6d8-dce8-40d7-9117-0ffd016fe886.aspx Part 2 - http://www.manuelabadia.com/blog/PermaLink,guid,eba2bb6b-7006-41ae-a035-532021eb5f42.aspx Part 3 - http://www.manuelabadia.com/blog/PermaLink,guid,e4f162b4-2adb-46d7-9d31-be32ff9b1347.aspx Part 4 - http://www.manuelabadia.com/blog/PermaLink,guid,45f5c9da-8a03-423f-b5b6-5882c4bd67e5.aspx I hope it helps. Manu Works beautifully, Thanks Manu.
Show quoteHide quote "Manu" wrote: > You don't have to instantiate the business object yourself. It will be > instantiated by ObjectDataSource infrastructure. > > When you work with a control like the GridView, you don't have to call > the methods from the ObjectDataSource. You should get the underlying > view and call the ObjectDataSourceView methods. > > The exception you're getting is becouse the ObjectDataSource Insert > method calls the ObjectDataSourceView Insert method with a null value, > so it doesn't have anything to insert. You should call the > ObjectDataSource Insert method with a dictionary containing the > parameters needed to populate your object. > > For example, if you are working with products and you want to insert a > product that has id, name, description and price, the dictionary you're > passing to the Insert method needs to have some of this entries. Then > the ODS will use them to create an instance of your product class and > set all the properties that have the same name as the entries in the > dictionary with their respective values. > > If you're a bit lost you can check my posts about the ODS and the new > data source controls (specially parameter merging in part 3 on the ODS > and DataSourceView and part 2 & 3 of the new data source controls). > > Post about the ODS: > > Part 1 - The basics - > http://www.manuelabadia.com/blog/PermaLink,guid,c72852ae-1fdd-4934-a715-f565ceaf21cc.aspx > Part 2 - Paging, Sorting, Parameters and Events - > http://www.manuelabadia.com/blog/PermaLink,guid,f002752d-1258-475d-9ec0-eee3bd98d0a4.aspx > Part 3 - Optimistic Concurrency, parameter merging, caching and design > time attributes - > http://www.manuelabadia.com/blog/PermaLink,guid,eaa3eed8-f997-43c4-8c30-78c2f72d0c86.aspx > Part 4 - Limitations, problems and possible solutions - > http://www.manuelabadia.com/blog/PermaLink,guid,32e83915-a503-403e-97c7-e20dcf2e0b7e.aspx > > Post about the new data source controls: > > Part 1 - > http://www.manuelabadia.com/blog/PermaLink,guid,678ed6d8-dce8-40d7-9117-0ffd016fe886.aspx > Part 2 - > http://www.manuelabadia.com/blog/PermaLink,guid,eba2bb6b-7006-41ae-a035-532021eb5f42.aspx > Part 3 - > http://www.manuelabadia.com/blog/PermaLink,guid,e4f162b4-2adb-46d7-9d31-be32ff9b1347.aspx > Part 4 - > http://www.manuelabadia.com/blog/PermaLink,guid,45f5c9da-8a03-423f-b5b6-5882c4bd67e5.aspx > > I hope it helps. > > Manu > > Manuel
I wonder if you can help me as well. I am using an ODS with a custom object as parameter to my business logic layer method. I want to contrive an insert in a GridView by constructing a new row using the EmptyDataTemplate and FooterTemplate. I have done this successfuly before using a simple button with an OnClick routine that builds the InsertParameters and then invokes the ODS Insert method - but only with simple type parameters. You say in your post that the answer is to call the ObjectDataSource Insert method with a dictionary containing the parameters needed to populate the object - but I am not clear how I do that since the Insert method does not take arguments. Do I need to do something using an ObjectCreating event handler? Jon Stranger Show quoteHide quote "Manu" wrote: > You don't have to instantiate the business object yourself. It will be > instantiated by ObjectDataSource infrastructure. > > When you work with a control like the GridView, you don't have to call > the methods from the ObjectDataSource. You should get the underlying > view and call the ObjectDataSourceView methods. > > The exception you're getting is becouse the ObjectDataSource Insert > method calls the ObjectDataSourceView Insert method with a null value, > so it doesn't have anything to insert. You should call the > ObjectDataSource Insert method with a dictionary containing the > parameters needed to populate your object. > > For example, if you are working with products and you want to insert a > product that has id, name, description and price, the dictionary you're > passing to the Insert method needs to have some of this entries. Then > the ODS will use them to create an instance of your product class and > set all the properties that have the same name as the entries in the > dictionary with their respective values. > > If you're a bit lost you can check my posts about the ODS and the new > data source controls (specially parameter merging in part 3 on the ODS > and DataSourceView and part 2 & 3 of the new data source controls). > > Post about the ODS: > > Part 1 - The basics - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,c72852ae-1fdd-4934-a715-f565ceaf21cc.aspx[/url] > Part 2 - Paging, Sorting, Parameters and Events - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,f002752d-1258-475d-9ec0-eee3bd98d0a4.aspx[/url] > Part 3 - Optimistic Concurrency, parameter merging, caching and design > time attributes - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,eaa3eed8-f997-43c4-8c30-78c2f72d0c86.aspx[/url] > Part 4 - Limitations, problems and possible solutions - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,32e83915-a503-403e-97c7-e20dcf2e0b7e.aspx[/url] > > Post about the new data source controls: > > Part 1 - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,678ed6d8-dce8-40d7-9117-0ffd016fe886.aspx[/url] > Part 2 - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,eba2bb6b-7006-41ae-a035-532021eb5f42.aspx[/url] > Part 3 - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,e4f162b4-2adb-46d7-9d31-be32ff9b1347.aspx[/url] > Part 4 - > [url]http://www.manuelabadia.com/blog/PermaLink,guid,45f5c9da-8a03-423f-b5b6-5882c4bd67e5.aspx[/url] > > I hope it helps. > > Manu > > [/B] -- jstranger ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------ Having now thought about this a bit more, I think my button.Click
handler needs to build the ODS.InsertParameters as a set of simple
types and then call the ODS.Insert method - and then have an
ODS.Inserting event handler that rebuilds the InsertParameters as a
custom object (as in the MSDN example under ODS.InsertMethod
property).
But the ODS.Insert still fails with 'no values to insert'. My button.Click code is approx as follows: Dim releases As ObjectDataSource = AlbumForm.FindControl("ReleasesEditDS") Dim parms as ParameterCollection = releases.InsertParameters parms.Add("parm1", ...) .. .. releases.Insert() Any suggestions as to what I am doing wrong? Jon jstranger wrote: Show quoteHide quote > *Manuel > > I wonder if you can help me as well. I am using an ODS with a custom > object as parameter to my business logic layer method. I want to > contrive an insert in a GridView by constructing a new row using the > EmptyDataTemplate and FooterTemplate. I have done this successfuly > before using a simple button with an OnClick routine that builds the > InsertParameters and then invokes the ODS Insert method - but only > with simple type parameters. You say in your post that the answer is > to call the ObjectDataSource Insert method with a dictionary > containing the parameters needed to populate the object - but I am > not clear how I do that since the Insert method does not take > arguments. Do I need to do something using an ObjectCreating event > handler? > > Jon Stranger > > "Manu" wrote: > > > You don't have to instantiate the business object yourself. It will > be > > instantiated by ObjectDataSource infrastructure. > > > > When you work with a control like the GridView, you don't have to > call > > the methods from the ObjectDataSource. You should get the > underlying > > view and call the ObjectDataSourceView methods. > > > > The exception you're getting is becouse the ObjectDataSource > Insert > > method calls the ObjectDataSourceView Insert method with a null > value, > > so it doesn't have anything to insert. You should call the > > ObjectDataSource Insert method with a dictionary containing the > > parameters needed to populate your object. > > > > For example, if you are working with products and you want to > insert a > > product that has id, name, description and price, the dictionary > you're > > passing to the Insert method needs to have some of this entries. > Then > > the ODS will use them to create an instance of your product class > and > > set all the properties that have the same name as the entries in > the > > dictionary with their respective values. > > > > If you're a bit lost you can check my posts about the ODS and the > new > > data source controls (specially parameter merging in part 3 on the > ODS > > and DataSourceView and part 2 & 3 of the new data source > controls). > > > > Post about the ODS: > > > > Part 1 - The basics - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,c72852ae-1fdd-4934-a715-f565ceaf21cc.aspx[/url] > > Part 2 - Paging, Sorting, Parameters and Events - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,f002752d-1258-475d-9ec0-eee3bd98d0a4.aspx[/url] > > Part 3 - Optimistic Concurrency, parameter merging, caching and > design > > time attributes - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,eaa3eed8-f997-43c4-8c30-78c2f72d0c86.aspx[/url] > > Part 4 - Limitations, problems and possible solutions - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,32e83915-a503-403e-97c7-e20dcf2e0b7e.aspx[/url] > > > > Post about the new data source controls: > > > > Part 1 - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,678ed6d8-dce8-40d7-9117-0ffd016fe886.aspx[/url] > > Part 2 - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,eba2bb6b-7006-41ae-a035-532021eb5f42.aspx[/url] > > Part 3 - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,e4f162b4-2adb-46d7-9d31-be32ff9b1347.aspx[/url] > > Part 4 - > > > [url]http://www.manuelabadia.com/blog/PermaLink,guid,45f5c9da-8a03-423f-b5b6-5882c4bd67e5.aspx[/url] > > > > I hope it helps. > > > > Manu > > > > * [/B] -- jstranger ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------ The Insert method of the ObjectDataSource doesn't take parameters, but
if you have defined them in the InsertParameters collection it will get them internally. If you obtain the ObjectDataSourceView you can call the Insert method passing a dictionary of parameters (the Insert method in the ObjectDataSource is just a call to the View with a null dictionary) Hope it helps, Manu. Manuel
Thanks for the reply. In fact I discovered my problem which was that I had forgotten to remove the DataObjectTypeName property from the ObjectDataSource. But while a Select still works fine without this property set (despite the fact that my 'get' method returns a custom object), an Update of course does not and has to be handled explicitly in the same way as an Insert. On the plus side, however, I can now simplify the parameters on a Delete. Wouldn't it be nice if we could specify a DataObjectTypeName separately for each CRUD operation? Jon Manu wrote: Show quoteHide quote > *The Insert method of the ObjectDataSource doesn't take parameters,
> but > if you have defined them in the InsertParameters collection it will > get > them internally. > If you obtain the ObjectDataSourceView you can call the Insert > method > passing a dictionary of parameters (the Insert method in the > ObjectDataSource is just a call to the View with a null dictionary) > > Hope it helps, > Manu. * -- jstranger ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------
GridView, ObjectDataSOurce, and enum parameter for select
Cant get user-entered values in GridView Fitting a character on a small button Scrolling DG w/a Fixed Header DataGrid1.DataSource = ds.Tables(2) GridView Multiple Select Buttons Treeview SelectedNodeChanged event not firing How can I create a new excel file in webbrowser? Help! About the webBrowser! Dynamically adding Views to Multiview control |
|||||||||||||||||||||||