Hi All
I have a project that is very similar to the Project Tracker in the book.
On a web page I have GridView bound to a CslaDataSource. My problem is that when I add a new item to the grid or edit an existing one, I do it on a separate web page and when I return to the web page with the grid it defaults to the first page which may not be the one containing my new/edited item.
I have added a GetPageNumber method to my business class so I can find out which page to display in the grid. What I can't find out is how go get at the object instance. I have cached the object in the session like the project tracker example and the CslaDataSource grabs this in its SelectObject method. How do I get at the object instance that the CslaDataSource is using so I can call its GetPageNumber method?
I am trying to do this in a base page class so I can use it in all my web pages so I can't just grab the cached business object. I pass the base page class method the grid, it gets the bound CslaDataSource but then I'm stuck. How do I go from the CslaDataSource to the CslaBusinessObject instance?
Cheers
Steve
If you are using the Session caching scheme from PTWeb you'd run into issues. That scheme only allows one object in Session at a time. When you are on the grid page that object would be your collection, but when you switch to the detail page the object would be replaced with the specific business object you are adding. When you return to the grid page Session would contain the newly added object, not the collection, and that would cause a reload of the collection.
Since you are using Session anway, why not use another Session variable to keep the last displayed grid page, so when you return to the grid form you can just use that value?
Things like tracking which page is displayed, or even which page contains a given item in a collection, are not the job of your business layer. Such behaviors would have no meaning at all in a web service or Windows Forms UI and so don't belong in your objects. They are purely UI artifacts, and so should be managed by the UI itself.
Good advice about moving the page display calc out of the BL. I'll do that.
I guess what I'm asking is the best way of determining what page a given item is on. The minimum I need to do is find out the position of the item in the collection and unless I can get that info from somewhere else I need to get it from the business object. The grid only contains the items being displayed. I can't see anything in the csladatasource that can help. I could have added a new item and returned to the grid page and need to find out which page the new item is on. I would have thought this was a common scenario for paging grid web pages and I'm still hoping to stumble on a magic property/method!
Thanks - just what I needed.
Steve
Copyright (c) Marimer LLC