locked
Advice on ObjectDataSource please RRS feed

  • Question

  • User-2024822571 posted

    Hi,

    I'm developing an ASP.NET web app using custom objects (BO) and a data access layer (DAL). For one reason or another i've selected the ObjectDataSource as my link from the presentation layer (PL) to the BO and hence ultimately to the DAL. So far it all works as expected. I can read the data, update it, create new objects and delete. Each of these actions is bound through the SelectMethod, DeleteMethod, etc. Sounds great, but I would also like to call some of the other methods exposed by my BO. e.g. Suspend(), Reinstate(), etc. but I don't know how to do that with the ObjectDataSource.

    I know I have reached the limit of my knowledge, but have I also reached the limit of the ObjectDataSource?

    I'm looking for advice on how to access my additional BO methods via the ObjectDataSource or alternatively advice on the most appropriate data binding approach to take.

    Thanks,

    Mike

    Wednesday, June 9, 2010 4:26 PM

Answers

  • User-1360095595 posted

    I haven't tried anything like this before so the following are just ideas:

    1. You might handle the click event of the button(s) and use a SqlCommand to do whatever update you want to the underlying tables.  It should be fairly simple since it's a simple UPDATE.  Or,

    2. The objectdatasource has UpdateMethod, UpdateParameters and Update().  Perhaps in the button(s) click event, you can set the UpdateMethod to point it to the "other" method you want to call, and populate the UpdateParameters collection accordingly, and then call Update().  This seems reasonable also.

    I hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 10, 2010 6:49 AM

All replies

  • User-1360095595 posted

    Well it depends under what circumstances, or event, you want to call them, and for what purpose. 

    Wednesday, June 9, 2010 5:04 PM
  • User-2024822571 posted

    Fair enough.

    I'm looking to create a list of my objects to populate a FormView. The aim is that I can page through the FormView until I find the object I wish to edit and put it into the EditTemplate. This works at the moment and I have bound the UpdateMethod of the ObjectDataSource to my objects Update() method to save all the fields back to the database. But I would like to add a couple of buttons to the EditTemplate to enable 'smaller' updates to the current object. By 'smaller' I mean to toggle one property of the object. In my example I have a user object and a 'smaller' update would be a suspend or reinstate method. These methods either add or remove a date/time from the corresponding database table via a SQL UPDATE statement.

    If you require more info then just let me know.

    Thanks,

    Mike

    Thursday, June 10, 2010 3:34 AM
  • User-1360095595 posted

    I haven't tried anything like this before so the following are just ideas:

    1. You might handle the click event of the button(s) and use a SqlCommand to do whatever update you want to the underlying tables.  It should be fairly simple since it's a simple UPDATE.  Or,

    2. The objectdatasource has UpdateMethod, UpdateParameters and Update().  Perhaps in the button(s) click event, you can set the UpdateMethod to point it to the "other" method you want to call, and populate the UpdateParameters collection accordingly, and then call Update().  This seems reasonable also.

    I hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 10, 2010 6:49 AM
  • User-2024822571 posted

    Thanks for the ideas. I reckon the second option sounds promising and i'll give it a go when I get back to my box. It sounds a little bit like a kludge as I would have thought if this were the recommended practice that the method names would be a little more generic, but it's worth a go.

    Am I trying to do something with the ODS that it isn't designed to do and if so is there a recommemded route to take?

    Mike

    Thursday, June 10, 2010 4:39 PM
  • User-2024822571 posted

    OK, a very late update. In the end I went with option 1) supplied my our esteemed colleague MetalAsp.Net. This entailed adding a click event to a button on the form and then handling that in the code. The result is what I had hoped for as I can now update a single property of the object. Admitidly it's not going through the object to do this, but it works and that's as much as I can hope for atthe moment.

    Thanks,

    Mike

    Saturday, December 18, 2010 3:24 PM