Page 1 of 1

Get the categories in order.

Posted: Mon May 24, 2010 10:51 am
by robgrigg
Hi,

I am currently using the

Code: Select all

CategoryCollection categories = CategoryDataSource.LoadForParent(categoryId, true);
methos to get the root category and then recurse on this to build a menu.

All is fine except I have just noticed that the categories are ordered as they wre created. not as they are organised in the admin screen.
In fact, changing the order in admion has no effect.

Can you tell me how I get the root category and the any other category by categoryId whilst preserving the order set in admin and also only including active categories.

Thanks.

R.

Re: Get the categories in order.

Posted: Mon May 24, 2010 12:02 pm
by mazhar
I guess LoadForParent doesn't support sort expression ability. Give a try to load categories as below

Code: Select all

CatalogNodeCollection categoryNodes = CatalogNodeDataSource.LoadForCategory(categoryId, "OrderBy ASC");
        CategoryCollection categories = new CategoryCollection();
        foreach (CatalogNode catalogNode in catalogNodes)
        {
            if (catalogNode.CatalogNodeType == CatalogNodeType.Category)
                categories.Add((Category)catalogNode.ChildObject);
        }