Why not do the counting in the database when you fetch the data.
As an example if you list states and want to have count of cities in the state as another column you can of course use grouping (GROUP BY clause) but also one easy way is to use a correlated scalar query. For example:
SELECT s.StateName,
( SELECT COUNT(*)
FROM tblCities c
WHERE c.StateName = s.StateName)
FROM tblStates s
Using the same idea I believe it would be easy to count the ads.