LLBLGenProDataSource2 event order

Posts   
 
    
Roman
User
Posts: 23
Joined: 19-May-2006
# Posted on: 14-Jul-2006 23:10:55   

Hello,

Here is a quote from the Pro ASP.NET 2.0 in C# book (bold font from there as well):

Essentially, data binding tasks take place in this order: 1. The page object is created (based on the .aspx file). 2. The page life cycle begins, and the Page.Init and Page.Load events fire. 3. All other control events fire. 4. The data source controls perform any updates. If a row is being updated, the Updating and Updated events fire. If a row is being inserted, the Inserting and Inserted events fire. If a row is being deleted, the Deleting and Deleted events fire. 5. The Page.PreRender event fires. 6. The data source controls perform any queries and insert the retrieved data in the linked controls. The Selecting and Selected events fire at this point. 7. The page is rendered and disposed.

What I found in LLBLGenProDataSource2 (an otherwise excellent control!) is that data retrieval/selection happens before Page.PreRender, which in some circumstances might cause an unnecessary data lookup. Let me explain.

I have a grid bound to said LLBLGenProDataSource2 object, which uses a TypedList as a source of data. LivePersistance is true by default and everything is fine and dandy. Server-side paging just works and everyone's happy. Now I want to add a delete button to each row in the grid. Since typed lists are read-only, I'm relying on the grid to fire Grid_RowDeleting event at which point I add custom logic to delete the appropriate entity.

Unfortunately once the page loads after the delete, I notice that the deleted item is still in the list, i.e. the data is stale. Putting the debugger and SQL Profiler to work, I find that the data source object performs the SELECT before the grid's RowDeleting event is fired and definitely before Page.PreRender.

My (hopefully) temporary fix is to set the data source's Refetch property to true, which causes another SELECT to fire, this time after Page.PreRender. So now I have made two fetches for one set of data.

Any reason for the existing event order in LLBLGenProDataSource2? Logically, I have to agree with the book - update/delete operations should all be performed prior to data retrieval, so only the final data is received.

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 15-Jul-2006 09:58:26   

The control has no logic in what to do at which point, unfortunately. It simply gets calls to ExecuteSelect, ExecuteUpdate, ExecuteDelete and ExecuteInsert. When such a call arrives it performs the request and returns. It's more or less a slave of the bound control.

So when a bound grid first fetches the data, and thus calls ExecuteSelect, a select is performed. If then the grid has to do a delete and calls ExecuteDelete, the delete is done. However if the grid then doesn't refresh itself, you keep the old data.

The MS datasourcecontrols work exactly the same. They too don't cache commands till a given point as the list suggests. The list you showed is simply a RESULT of how the bound controls work with the datasourcecontrols: the actions are initiated by the bound grid etc., and performed by the datasourcecontrols which then simply wait for the next action to perform.

In your case, I think I know what's wrong: the typedlist is readonly. So when the grid executes ExecuteDelete, nothing happens.

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 03-Aug-2008 16:53:07   

I am having an identical problem, except using a TypedView. I have code running on a Delete LinkButton click which calls a delete to the database. However, when the GridView refreshes, the row is still there because a refetch didn't happen.

I've tried calling drid.DataBind() and tried setting ds.Refetch = true, and neither one of these works. I have also disabled viewstate on the GridView, doesn't work.

How am I supposed to get the refresh of data to happen?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Aug-2008 22:34:05   

Please post some info (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7717): - LLBLGenPro version and RuntimeLibraries build version - The code snippet where you Delete some row. - The code snippet where you Refresh the DataSource/Grid - Declarative ASPX of the Grid and LLBLGenProDataSource (if you are using it).

In the future, plesae don't open old threads, instead of that open a new one wink

David Elizondo | LLBLGen Support Team