A question that I have been posting on asp.net has been...
Is there any way to use the same select method for both the SelectMethod and SelectCountMethod when paging is enabled with the ObjectDataSource?
You would think there has to be a way to do this. Can I pass a select parameter by reference that returns a count? Or if I am returning a collection, have one of the properties of the collection be a TotalCount property and somehow use that?
I don't like the idea of having to create a 2nd companion method for each select method that takes the same parameters. Actually that is pretty weak if I am forced to do that. I guess you could overload a GetCount method but that would require having rather generic parameters being passed in like "ID" instead of "customerID". I'd really rather not do that though.
-- a member of the ASP.NET team had this answer for my question-------------------------------
If you want to use the ObjectDataSource EnablePaging=true feature, you will need to define a separate SelectCountMethod for the select operation. <snip>
We did consider a design pattern where the Select method included an output parameter for the total count, but decided against this pattern, because you typically only want to return the total row count on the first request for data, and not subsequent requests. A single method would have meant that the total count is always calculated, even when it is not needed or used. <snip>
I am sad to see that they didn't continue with the 2nd idea, as more and more users start adopting the ObjectDataSource, they will soon realize the above. It's not difficult to add logic to the select method to check if the totalCount != 0, if so then just pass the value back and not re-query the database..
If anyone has thoughts on how to have the SelectCountMethod and SelectMethod use the same Method that would be awesome. I've been racking my brain trying to figure out a way of doing this without diving deep into the objectdatasource. You would really be helping a brother out!
Winner gets a prize.. an "atta boy" or "atta girl"