Editable GridView with ObjectDatasource and Update method parameters.

Recently I posted Some workaround for ObjectDataSource: could not find a non-generic method '...' .
Sinse that I done some investigation to understand better the reason of the problem and possible workarounds. Most of them are posted in thread “Dataset + ObjectDatasource + GridView + ASP.NET 2” .
The problem  perfectly described here. And it is reported to MS, but they don't want to address it.

Actually Update code trying to executeby ASP.NET  from ObjectDataSource very depends on fields and field properties, declared in GridView.
If field has ReadOnly=true or Visible=false, it is not expected as a parameter to Update method and causes the error
System.InvalidOperationException: ObjectDataSource '...' could not find a non-generic method 'Update' that has parameters: ....
The reason is that readonly and invisible properties are not stored in ViewState and are not available on the time of Update parameters are populated.( I beleive that MS could extract read-only fields data to submit to pass as Update parameters, but they do not in this version).
Detailed description about ObjectDataSources parameters can be found in Manuel Abadia's blog.

So my approach is the following (in general following the tutorial “Working with Data in ASP.NET 2.0 :: An Overview of Inserting, Updating, and Deleting Data”  )  :
1.  Create the TableAdapters in the DAL (see Creating a Data Access Layer tutorial)

2.On the ASPX/ASCX page create ObjectDataSource and GridView.

3.Customize the GridView fields to specify the properties as ReadOnly,Visible=false, DataKey as required by busuness/UI requirements.

4. Run it and test inline Update method. It will return “could not find a non-generic method 'Update' that has parameters” error, which will list names and order of parameters that are required by gridview settings.

5. Return to strongly-typed dataset  XSD designer and add new Update adapter method with the parameters that gridView expects.
6. In ObjectDataSource change Update method to the new adaptor Update method. 

Update: I've posted related "Why we are getting ObjectDataSource: could not find a non-generic method 'Update'"

posted @ Friday, September 01, 2006 10:32 AM

Print

Comments on this entry:

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by Jkey at 9/8/2006 7:10 PM
Gravatar
I have just moved from 1.0 to 2.0, and discovered that this was a problem I shared with many others.

I see this has been a great problem in the past, with various suggestions to creative solutions. No one has taken the time to provide a correct answer, though. It took me two days to solve the problem, which is that the gridview requires your sprocs params to match the names of the table columns AND that they include params for all the columns, whether you use them or not(!). This I found out from reading this article by Esposito: http://msdn.microsoft.com/msdnmag/issues/04/08/GridView/

Hope this helps someone.

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by neta at 1/18/2007 10:34 PM
Gravatar
i hv same problem
but
not solveed................
why
tell me why

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by JD at 2/6/2007 1:12 AM
Gravatar
Your solution solved my problem...and it's nice an simple. Thanks a lot.

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by Peter Schmidt at 2/23/2007 10:45 PM
Gravatar
YOU ARE A STAR...Adding my own update function to my Adaptor solved the problem !!

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by Adam George at 3/16/2007 11:55 PM
Gravatar
Just add a business object class in the App_Code folder, use that as the objectdatasource typename, then call the update method with the necessary different parameters from the Object class update function.

# re: Why we are getting ObjectDataSource: could not find a non-generic method 'Update'.

Left by Michael Freidgeim at 7/18/2007 1:25 AM
Gravatar
Posted by Microsoft on 5/05/2007: "We have fixed the issue with an additional update function.
The fix will be available in the next VS release." https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=260674

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by John Ward at 7/22/2007 5:43 PM
Gravatar
One problem. I need to set UpdatedBy and DateUpdated in the RowUpdating event before updating a record. These are bound, hidden columns by necessity.

That said, the process you elaborated shines some light on a way to solve some problems. thanks.

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by Steve D at 7/26/2007 1:26 AM
Gravatar
To John Ward -- At first I was trying to set values like this in the RowUpdating event.

Later on I realized that I can set them in the SQL statement I build, or pass them as params to a SProc, using values derived elsewhere (but not from the Grid). E.g., set DateUpdated to Now() or the C# equiv, and set the UpdatedBy to a value retrieved from a session variable or function that gets the authenticated userid.

HTH

Steve D
Somerville, NJ

# re: Editable GridView with ObjectDatasource and Update method parameters.

Left by Lani at 2/13/2008 5:31 PM
Gravatar
I needed to set UpdatedBy as well. What I did was to put this in my RowUpdating event handler:

e.NewValues.Add("UpdatedBy", "newname");

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 3 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910