ElementsFetched

Posts   
 
    
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 23-Oct-2009 17:47:38   

Hi,

I am using an LLBLGenProDatSource2 control on a web page as the data source for a telerik grid.

LivePersistence is set to true

The control is used to populate the grid with a number of items from a view called vwSearch. I am using paging to restrict the number of items displayed to 10 per page.

What I am trying to do is record when an item is displayed so that I can provide users with stats as to the number of times an item has been viewed by people using the webiste. I am having problems doing this with the Telerik PreRender event and so I would try to do it from the LLBLGen control instead.

My thinking is that I can use the event ElementsFetched on the LLBLGenProDatSource2 control to step through the 10 items that are returned for the current page and record details for each of the 10 items accordingly.

What code do I need to put into the ElementsFetched routine to step through all of the items returned by the LLBL query engine and pick up a field value in the view called "AttractionID". Any code snippets would be greatly appreciated and I can adapt for my needs.

I hope this makes sense

Many thanks in advance

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Oct-2009 23:02:48   

Hi there,

Yes, you could subscribe to ElementsFetched. The code could be something like:

// here my view is InvoicesTypedView
InvoicesTypedView view = (InvoicesTypedView ) this.LLBLGenProDataSource21.TypedView;

// calculate the views of the customer HANAR
int total = 0;
foreach (InvoicesRow row in view)
{
    if (row.CustomerId == "HANAR") total++;
}

Or the Linq2Objects (.net 3.5) version:

// here my view is InvoicesTypedView
InvoicesTypedView view = (InvoicesTypedView)this.LLBLGenProDataSource21.TypedView;

// calculate the views of the customer HANAR
int totalLinq =  view.Where(v => v.CustomerId == "HANAR").Count();
this.Title = totalLinq.ToString();  
David Elizondo | LLBLGen Support Team
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 24-Oct-2009 10:08:45   

Excellent many thanks