Grid returns null properties that were not edited.

3 posts, 0 answers
  1. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 19 Dec 2012 Link to this post

    Hello Team;
    Let me first provide some info, before discussing my problem.

    Previously I had used EF and "ObjectCondext" for my Model. Then for each ASP Page that I needed DataSource, I had used ObjectDataSource (ODS). In the ODS declaration, I had identified the "Update" method which takes two parameters. One the modified object and the second the Original object.
    In the Update method first I would attach the Original object to my ObjectContext first and the call "ApplyCurrentValues" Method from ObjectContext and pass the modified object. This method would then compare the properties between the two objects and create the proper SQL update command to update only Modified properties.

    Now, with this new project, I'm using CodeFirst and DbContext and unfortunately DBContext does not have "ApplyCurrentValues" Method to pass two objects (before & after). It only takes the modified object.

    But I'm running into a serious problem with Telerik Grid in this situation. Let's say I have a customer object with 20 properties and three Foreign key properties. If I connect the Grid to ObjectDataSource and have only 5 properties as "Editable" in the grid, when I do an update, the grid returns me an object with all the properties, but all the other 15 properties that were not editable and bound to TextBox (with Bind), they all become Null, including all my Foreign key fields.
    In most cases, I don't need to have all the properties shown, Especially the foreign key values.

    How do I solve this problem, that the grid returns me the original values of those properties that were not changed? 
    ..Ben
  2. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 19 Dec 2012 Link to this post

    Perhaps, I can summarize the problem as following:
    When I pass and object to the grid, and properties (including those holding Foreign key values) that are not bound to grid columns, the grid replaces the original values with null and passes me back and object with only properties that were bound to grid.

    In many cases I don't need to display ALL the properties. How can I solve this? What am I doing wrong?
    Thanks!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 20 Dec 2012 Link to this post

    I came up with a workaround this problem that I'd like to share with others, but not sure if this the best. Hoping something less manual.

    Basically, once the grid passes back the object to the middle tier repository class, I have to read a fresh copy of that class from the database and then replace those changed properties from the object returned from grid to the new object and then save the new object back. Sounds like a lot of manual work.
    But is this how to work with ObjectDataSource and Telerik grid?
    Thanks!
Back to Top