Data Source Web Part not filtering by category

Eric Conklin asked on September 3, 2020 15:15

I have a pages data source web part on my blog that grabs blog posts from the folder. From there it hands them off to a basic repeater that gives a snippet of text and an image for each blog post.

I have category links on the sidebar that the user can click to grab a specific category. When you click one, it modifies the current page URL by appending ?categoryid=24 to the end of the query.

The pages data source has the following where condition:

('{%ToInt(categoryid, "")%}' = 0 AND '{%categoryname%}'='') OR (DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID = {% ToInt(categoryid) %}))

It is not recognizing the category id query using that where condition.

Does anyone have any idea why this might be? I don't think I'm trying to do anything particularly complex - just filter by category when the user clicks the category.

Correct Answer

Liam Goldfinch answered on September 3, 2020 17:25

Hi Eric,

Have you tried checking this page for macro syntax? https://docs.kentico.com/k12sp/macro-expressions/macro-syntax

You should probably be using one of the following to resolve the querystring value in a where condition:

  • {% QueryString.categoryid %}
  • {% categoryid %} - for this one to work, replace the % character with ? character (this website seems to replace ? with %)
0 votesVote for this answer Unmark Correct answer

Recent Answers


Eric Conklin answered on September 3, 2020 18:13

Hey, thanks to the above answer I changed my code to the following:

('{%ToInt(QueryString.categoryid, "")#%}' = 0 AND '{%categoryname%}'='') OR (DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID = {% ToInt(QueryString.categoryid) #%}))

I had to shorten it but the correct answer worked fine for me.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.