This topic is locked

How to count the number of retrieved in a list view?

3/17/2023 5:26:14 AM
ASPRunner.NET General questions
david powell author

Hi - I am not sure of the most effective way of doing this and cant find any hits on it....

I have a table of addresses.
Having done a simple search on that table, the results appear in a list view.
A record is then selected and another page opened by clicking a 'use this' button on the list page.

I want to be able to trigger the same 'use this code' without user intervention if there is only one match in the search result.

I can get to the data in the search result in the 'after record processed' action of the list.... but how do I count the number of rows in the dataset?

Many thanks for anyone who can help - or if there is a simpler way of doing this that would be even better!


david powell author 3/18/2023

I think I have a solution - use strWhereClause in beforesql event of the list and run my own query on the dataset with a count() . If unique then run it again this time with select * and the strWhereClause, execute appropriate code, and redirect to the next page.

admin 3/18/2023

Yes, this is a viable approach. You don't even need to retrieve the same dataset, you can do a simpler query:
select count(*) from tablename where ...

david powell author 3/18/2023

I tried using a fetchAssoc() command for a dataset but for some reason it failed to run from the beforesql event.

However my next approach was to set a SEssion variable to 0 in the beforesql event, then increment it by one for each afterrecord processed.

Then in the beforedisplay if the variable was 1 , run whatever code and go from there

That worked!

But thank you...