CategoryInfoProvider Select only Enabled Categories

Diane Cogswell asked on June 27, 2014 10:35

We have a site that generates dropdown selects from the Categories in Kentico. It's currently showing all categories, even ones that do not have the "enabled" checkbox selected. The code is using the CategoryInfoProvider.GetChildCategories Method. How would I update it to select just enabled categories?

var mainCategories = CategoryInfoProvider.GetChildCategories(ParentCategoryId, string.Empty, "CategoryLevel, CategoryOrder", 999, string.Empty, CMSContext.CurrentSiteID);

Correct Answer

Adam Gitin answered on June 29, 2014 08:20


You can use the WHERE ->

var mainCategories = CategoryInfoProvider.GetChildCategories(ParentCategoryId, "CategoryEnabled = 1", "CategoryLevel, CategoryOrder", 999, string.Empty, CMSContext.CurrentSiteID);

Hope this helps.

1 votesVote for this answer Unmark Correct answer

Recent Answers

Martin Danko answered on June 29, 2014 08:45

Hello Phillop,

as Adam correctly suggested, you can use the WHERE condition of mentioned API method.

GetChildCategoriesInternal(Int32, String, String, Int32, String, Int32)

categoryId (Int32) - ID of the category to get child categories for.
where (String) - Where condition.
orderBy (String) - Order by expression.
topN (Int32) - Number of records to be selected.
columns (String) - Columns to be selected.
siteId (Int32) - Site ID.

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Diane Cogswell answered on June 30, 2014 10:43

Adam thanks for the answer and Martin thanks for the additional info. I wasn't sure of the syntax and had no luck finding other examples. Worked like a charm. Thanks to you both again.

0 votesVote for this answer Mark as a Correct answer

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