API
Version 7.x > API > Macro QueryString DataSource View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
joe@jmawebtechnologies.com - 1/27/2013 9:45:26 AM
   
Macro QueryString DataSource
Hi,

I would like to filter events by price. Here is my WHERE clause:
WHERE Price <= {% QueryString.GetValue("Price") %}

1. How do I convert price to a decimal?

2. How do I see if QueryString.GetValue("Price") is null, then remove the where clause?

User avatar
Kentico Legend
Kentico Legend
Accepted solutionAccepted solution
Brenden Kehren - 1/29/2013 4:00:31 AM
   
RE:Macro QueryString DataSource
The proper query string macro should look like this:
{%ToDouble(Price, "10.2")%}
The 10.2 is the default value if it doesn't find a value. If there is no value in the querystring, you could just set the default to 0.0 so no products display or a large value like 1,000,000 so all your products display.

User avatar
Kentico Support
Kentico Support
kentico_janh - 1/29/2013 4:59:14 AM
   
RE:Macro QueryString DataSource
Hello,

You can take advantage of the ToDouble method in K# which return a default value if no Price query string is defined, so then you can specify the WHERE clause which matches your condition everytime:
{% QueryString.GetValue("Price").ToDouble(0.0, "en-us") %}

Best regards,
Jan Hermann