Last post Jan 11, 2007 08:40 AM by UAE001
Dec 10, 2006 10:45 PM|muzaffarm|LINK
I have generated some classes by running BLINQ against a database that I would like to use as ObjectDataSource for GrideView. The problem is that it works as long as I have all the columns listed in the GridView but as soon as I take any of the columns
away, it starts to complain that it could not find update method that takes parameter of type xxx. I have read the post at
Row not found or changed that suggests that in order to have only selected columns displayed in the GridView, I need to chang the ConflictDetection property of the ObjectDataSource to ConflictDetection ="OverwriteChanges" instead of "CompareAllValues" and
also change the UpdateCheck:=System.Data.DLinq.UpdateCheck.Never on each of the columns in my class. I have done all that but still have problems updating the row. The problem is that when I try to update a row and put a debug on
DataSource1_Updating event and quick watch e (ObjectDataSourceMethodEventArgs) it comes back with an object of right type but with no values initialized apart from the key field.
Here is what I have added to all properties on my class including the key column:
Problem with updating records
Dec 11, 2006 09:49 PM|phuff|LINK
The object created by the ObjectDataSource will have only property values for those columns that you have displayed in the GridView. The GridView and ObjectDataSource store values for those properties in the UI, so if you turn off those columns, the values
aren't there to be populated in the ObjectDataSource's Update event. This is a tradeoff of making columns invisible.
One way to get around this is to set columns whose properties you want to store, but you don't want to change or display, in the DataKeyNames property of the GridView. DataKeyNames takes a comma-separated list of columns you wish to save off, and those
values will be passed back to the ObjectDataSource in addition to the columns you have displayed.
Hope this helps...
Dec 12, 2006 02:32 AM|muzaffarm|LINK
Thank you very much for your response. It did not solve my problem entirely but gave me enough of a pointer to realize that the problem I have is not related to the ObjectDataSource, is is actually to do with the way I am creating my GridView control. What
I am trying to do is that I am trying to programatically create templated columns within my GridView control. Here is the code:
Private Sub GridView1_Init(ByVal sender
ByVal e As System.EventArgs)
'This collection gets set somewhere else that gets used here
This displays data correctley in the GridView both in normal as well as edit mode. When I try to update the row currently in edit mode, the row comes back with an empty new values collection.
If I do the same thing with the same data source and same columns in declarative fashion, every thing works fine and the new values get returned without any problem. Just as a reference, I am pasting the declarative code below.
EmptyDataText="No records were returned."
There might be something very simple that I am missing here, but it is driving me completely crazy at the moment. I would greatly appreciate if you could help me in this regard.
Dec 12, 2006 11:37 AM|erdsah88|LINK
objectdatasource is really tricky. zxcvbn
Dec 12, 2006 11:38 AM|erdsah88|LINK
how long have been using BLINQ?
Dec 12, 2006 05:14 PM|muzaffarm|LINK
Dec 12, 2006 08:38 PM|phuff|LINK
Muzaffarm, dynamically created TemplateFields do not save off values because of how templates are instantiated. As you have found, this means that declarative fields work correctly, but your dynamic TemplateFields do not hand old values to your data source.
You can get around this two ways: either dynamically create another type of field (BoundField or something similar), or declare your TemplateFields on your page. If neither of these solutions works for you, you can fall back to pulling the old values out
of the UI in code on the OnRowEditing event and saving off old values in ViewState or some other data storage mechanism.
I know this is less than ideal for your application, and I aplogize, but I hope one of these workarounds will work for you.
Jan 11, 2007 08:40 AM|UAE001|LINK
I just started to use Blinq and I had the same problem with updating and I searched for best solution for it. So what I did to work around this issue is to retrieve
the object using the GET method in the UPDATE method in StaticMethods.cs. for example:
// This method updates a record in the table.
original_x = GetCustomer(original_x.CustomerID);
I hope this solution is will be helpfull.