Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

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 on Friday, September 1, 2006 10:32 AM ASP.NET | Back to top


Comments on this post: Editable GridView with ObjectDatasource and Update method parameters.

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting 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.

Left by Jkey on Sep 08, 2006 7:10 PM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting Gravatar...
i hv same problem
but
not solveed................
why
tell me why
Left by neta on Jan 18, 2007 10:34 PM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting Gravatar...
Your solution solved my problem...and it's nice an simple. Thanks a lot.
Left by JD on Feb 06, 2007 1:12 AM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting Gravatar...
YOU ARE A STAR...Adding my own update function to my Adaptor solved the problem !!
Left by Peter Schmidt on Feb 23, 2007 10:45 PM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting 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.
Left by Adam George on Mar 16, 2007 11:55 PM

# re: Why we are getting ObjectDataSource: could not find a non-generic method 'Update'.
Requesting 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
Left by Michael Freidgeim on Jul 18, 2007 1:25 AM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting 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.

Left by John Ward on Jul 22, 2007 5:43 PM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting 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
Left by Steve D on Jul 26, 2007 1:26 AM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting 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");
Left by Lani on Feb 13, 2008 5:31 PM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting Gravatar...
I have datagrid when I hide some fields , and press update on the gridview the hidden field value is set to Null , Please help.
Left by mohamad ayash on Feb 21, 2009 9:56 AM

# re: Editable GridView with ObjectDatasource and Update method parameters.
Requesting Gravatar...
mohamad,
Are you using visible=false or hidden fields?
For fields with visible=false it is a known issue.
See http://forums.asp.net/p/936037/1386717.aspx
answer 04-22-2006, 8:41 PM
Left by Michael Freidgeim on Feb 21, 2009 12:51 PM

# Grid View With Dataset Update Not working
Requesting Gravatar...
i hv problem in gridview where i cant edit the dataset in templete field i hv not any code which i post in rowupdating & rowupated event plz guide who can i solve this Problem
Left by Anwer on Dec 22, 2009 4:28 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net