Skip to main content

Selecting a Query at Runtime

Now, we need to modify the TopPicks page to dynamically select the right query. We do this by changing the queryname attribute of the <csp:query> tag.

We earlier specified the query name with the literal value “TopFilms”.

—TopPicks.csp—
TopPicks.csp
<html> <body>
<h2><font color="#0000FF">Today's Top Picks</font></h2>
<table border=0>
<csp:query name=FilmList classname="Cinema.Film" queryname="TopFilms">
<csp:while condition="FilmList.Next()"> ... </csp:while>
</table>
</body> </html>

Now, instead, the query name will be determined by the value of the Query variable. We also specify that the P1 parameter, which is used in our TopCategory query, will have the value of the CatID variable.

—TopPicks.csp—
TopPicks.csp
<html> <body>
<h2><font color="#0000FF">Today's Top Picks</font></h2>
<table border=0>
<csp:query 
        name=FilmList 
        classname="Cinema.Film" 
        queryname='#(Query)#' 
        P1="#(CatID)#">
<csp:while condition="FilmList.Next()"> ... </csp:while>
</table>
</body> </html>
FeedbackOpens in a new tab