Update problem using BLINQ generated classes as ObjectDataSource for GridView

Last post 01-11-2007 8:40 AM by UAE001. 7 replies.

Sort Posts:

  • Angry [:@] Update problem using BLINQ generated classes as ObjectDataSource for GridView

    12-10-2006, 10:45 PM
    • Loading...
    • muzaffarm
    • Joined on 09-17-2006, 11:44 PM
    • Posts 3

    Hi,

     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:

    <Column(Name:=

    "chargeable_rate", Storage:="_ChargeableRate", DbType:="Decimal(18,0) NOT NULL", UpdateCheck:=System.Data.DLinq.UpdateCheck.Never)> _

     Any suggestions?

    Regards

     

  • Re: Update problem using BLINQ generated classes as ObjectDataSource for GridView

    12-11-2006, 9:49 PM
    • Loading...
    • phuff
    • Joined on 06-11-2002, 12:39 PM
    • Redmond, WA
    • Posts 547
    • AspNetTeam

    Muzzaffarm-

    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...

    Polita Paulus

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Update problem using BLINQ generated classes as ObjectDataSource for GridView

    12-12-2006, 2:32 AM
    • Loading...
    • muzaffarm
    • Joined on 09-17-2006, 11:44 PM
    • Posts 3

    Hi Polita,

     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 As Object, ByVal e As System.EventArgs) Handles GridView1.Init

    InitialiseColumns()

    End Sub

     

    Private

    Sub InitialiseColumns()

    'This collection gets set somewhere else that gets used here

    If IoColumns IsNot Nothing Then

    For Each LoSetting In IoColumns

    Dim LoTemplate As New TemplateField

    LoTemplate.HeaderTemplate =

    New LabelTemplate(DataControlRowType.Header, LoSetting.ColumnHeading)

    LoTemplate.ItemTemplate =

    New LabelTemplate(DataControlRowType.DataRow, LoSetting.DataColumnName)

    LoTemplate.EditItemTemplate =

    New TextBoxTemplate(LoSetting.DataColumnName)

    GridView1.Columns.Add(LoTemplate)

    Next

    End If

    End Sub

    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.

     

    <asp:GridView runat="server" DataSourceID="ObjectDatasource1"

    ID="GridView1"

    AllowSorting="True"

    EmptyDataText="No records were returned."

    AutoGenerateColumns="False"

    AllowPaging="True">

    <Columns>

    <asp:CommandField ShowEditButton="true" />

    <asp:BoundField DataField="RowKey" HeaderText="RowKey" SortExpression="RowKey" />

    <asp:BoundField DataField="ChargeableRate" HeaderText="ChargeableRate" SortExpression="ChargeableRate" />

    <asp:BoundField DataField="Gridrowid" HeaderText="Gridrowid" SortExpression="Gridrowid" />

    <asp:BoundField DataField="ContactPhone" HeaderText="ContactPhone" SortExpression="ContactPhone" />

    <asp:BoundField DataField="StandardRate" HeaderText="StandardRate" SortExpression="StandardRate" />

    <asp:BoundField DataField="ParentKey" HeaderText="ParentKey" SortExpression="ParentKey" />

    <asp:BoundField DataField="HearAboutUs" HeaderText="HearAboutUs" SortExpression="HearAboutUs" />

    <asp:BoundField DataField="WhoModified" HeaderText="WhoModified" SortExpression="WhoModified" />

    <asp:BoundField DataField="BookingReference" HeaderText="BookingReference" SortExpression="BookingReference" />

    <asp:BoundField DataField="DateModified" HeaderText="DateModified" SortExpression="DateModified" />

    <asp:BoundField DataField="ConsentReceived" HeaderText="ConsentReceived" SortExpression="ConsentReceived" />

    <asp:BoundField DataField="Organisation" HeaderText="Organisation" SortExpression="Organisation" />

    <asp:BoundField DataField="ContactPerson" HeaderText="ContactPerson" SortExpression="ContactPerson" />

    <asp:BoundField DataField="WhoCreated" HeaderText="WhoCreated" SortExpression="WhoCreated" />

    <asp:BoundField DataField="AwareOfCost" HeaderText="AwareOfCost" SortExpression="AwareOfCost" />

    </Columns>

    </

    asp:GridView>

    <

    asp:ObjectDataSource runat="server"

    SelectCountMethod="GetAllCount"

    DeleteMethod="Delete"

    SortParameterName="sortExpression"

    SelectMethod="GetAll"

    ID="ObjectDatasource1"

    EnablePaging="True" UpdateMethod="UpdateRow"

    OldValuesParameterFormatString="original_{0}"

    InsertMethod="Insert" DataObjectTypeName="YouthsafeTest.YsPresentation" TypeName="YouthsafeTest.YsPresentation" >

    </

    asp:ObjectDataSource>

    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.

    Thanks

    Muzaffar

  • Re: Update problem using BLINQ generated classes as ObjectDataSource for GridView

    12-12-2006, 11:37 AM
    • Loading...
    • erdsah88
    • Joined on 12-12-2004, 11:18 AM
    • ISTANBUL
    • Posts 887

    objectdatasource is really tricky. zxcvbn

    Satılık,Kiralık emlak ilanlari
  • Re: Update problem using BLINQ generated classes as ObjectDataSource for GridView

    12-12-2006, 11:38 AM
    • Loading...
    • erdsah88
    • Joined on 12-12-2004, 11:18 AM
    • ISTANBUL
    • Posts 887

    how long have been using BLINQ?

    Satılık,Kiralık emlak ilanlari
  • Re: Update problem using BLINQ generated classes as ObjectDataSource for GridView

    12-12-2006, 5:14 PM
    • Loading...
    • muzaffarm
    • Joined on 09-17-2006, 11:44 PM
    • Posts 3
    I have been using it since July 2006.
  • Re: Update problem using BLINQ generated classes as ObjectDataSource for GridView

    12-12-2006, 8:38 PM
    • Loading...
    • phuff
    • Joined on 06-11-2002, 12:39 PM
    • Redmond, WA
    • Posts 547
    • AspNetTeam

    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.

    Polita Paulus

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Update problem using BLINQ generated classes as ObjectDataSource for GridView

    01-11-2007, 8:40 AM
    • Loading...
    • UAE001
    • Joined on 05-27-2004, 10:05 AM
    • Posts 1

    Hi,

    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.

    // Change this method to alter how records are updated.

    public static int Update(Customer original_x, Customer x)

    {

    northwind db = northwind.CreateDataContext();

    original_x = GetCustomer(original_x.CustomerID);

    db.Customers.Attach(original_x);

    original_x.CustomerID= x.CustomerID;

    db.SubmitChanges();

    return 1;

    }

    I hope this solution is will be helpfull.

    Thanks.

Page 1 of 1 (8 items)
Microsoft Communities
Page view counter