Remove Subcategories from CategoryGridPage4.ascx
Posted: Mon Jul 28, 2008 5:43 pm
I am using the 'CategoryGridPage4.ascx' to display products because I want to see the summary field displayed for each product. The only issue is that that subcategories are showing up in the list as a hypertext link. If I click the link it shows me all the products for that subcategory. I would like to avoid these subcategories from showing up in the list.
I was thinking that if the Category has a parent id, then I know it is a subcategory so I shouldn't display it. So I modified the ascx page within the Page_Init call to check the ParentId value. Since the ParentId value of 0 means it is a top category, I figured this would work! But it didn't
The code I added is to the 2nd if statement below "(node.Category.ParentId == 0)".
That didn't work, so what would be my best approach?
I was thinking that if the Category has a parent id, then I know it is a subcategory so I shouldn't display it. So I modified the ascx page within the Page_Init call to check the ParentId value. Since the ParentId value of 0 means it is a top category, I figured this would work! But it didn't
The code I added is to the 2nd if statement below "(node.Category.ParentId == 0)".
That didn't work, so what would be my best approach?
Code: Select all
foreach (CatalogNode node in _Category.CatalogNodes)
{
if (node.Visibility == CatalogVisibility.Public)
{
bool addNode = true;
if ((node.CatalogNodeType == CatalogNodeType.Category) && (node.Category.ParentId == 0))
{
addNode = (CatalogDataSource.CountForCategory(node.CatalogNodeId, true) > 0);
}
if (addNode) _ContentNodes.Add(node);
}
}