I’m writing a reusable control – lets call it MyListView – inherited from standard ASP.NET ListView control. It’s datasource is always set to a LinqDataSource and I need to calculate total value for a specific column (sum of all values for that column). Which way is the best to calculate a total value? I was thinking of OnItemDataBound event and computing total there using global variable, but I also need paging in MyListView (using standard Pager control) and this event is fired only for rows on currently visible page, not for all rows in the datasource. I also don’t want to calculate total sum in code behind of ASPX page, I want to just specify a column name in aspx, and MyListView will automatically compute total value for the column.
Thank you for help!
IF you’re using pagination it’s not easy to have that result. I think you should consider to put the row used for totals outside the ListView (so you can use LINQ to compute totals too, I guess you don’t want to enumerate all items to compute a total when it can be done quickly on SQL side).