4

I have an EntityDataSource with OnSelected event (fired after finished query). The event handler has event args of type EntityDataSourceSelectedEventArgs e. Query runs fine without error and the IEnumerable e.Results contains 1 object (I can run through a non-empty foreach-loop) but e.TotalRowCount returns -1.

Does somebody have an idea what this means and what information TotalRowCount actually expresses? How can I determine the number of selected objects if not by using TotalRowCount?

Slauma
  • 175,098
  • 59
  • 401
  • 420

1 Answers1

3

From http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.entitydatasource.selected(VS.100).aspx:

    The TotalRowCount property of the EntityDataSourceSelectedEventArgs 
object shows the total number of objects in all pages, regardless of the 
values passed by the data-bound control for paging. 

    TotalRowCount is only retrieved if the data-bound 
control needs it, such as if paging is enabled.

Is your data-bound control using paging?

DaveB
  • 9,470
  • 4
  • 39
  • 66
  • No, it doesn't use paging. OK, thanks, that explains why TotalRowCount is useless without paging. But how can I determine the number of objects then? – Slauma Mar 02 '10 at 22:13
  • Since e.Results is an IEnumerable, how about e.Results.Count() ? – DaveB Mar 02 '10 at 22:55
  • e.Results is an `System.Collections.IEnumerable` which does not seem to have a `Count()` method or property - in contrast to `System.Collections.Generic.IEnumerable`. – Slauma Mar 02 '10 at 23:44
  • Try importing the Linq namespace and using it's extension method. – DaveB Mar 03 '10 at 04:32
  • 1
    System.Linq and System.Data.Linq was already imported but it doesn't help. The extension method seems only to be available for the generic version of IEnumerable but not for the non-generic version. After looking at various other discussions here about IEnumerable I think the only way is really to iterate through IEnumerable and to count the objects. – Slauma Mar 03 '10 at 12:58
  • This post may be of some help if you want to write your own extension method. http://stackoverflow.com/questions/1155619/ienumberable-to-something-that-i-can-get-a-count-from – DaveB Mar 03 '10 at 19:52