I have managed to solve this.
The way I have imlemented is that I have the very top level categories are in the the CMS. And then I use the categories defined on those pages to build the child categories like below
CatalogNodes nodeslevel2 = CatalogContext.Current.GetCatalogNodes(catalogs.Catalog.Name, pTopCatPage.URLSegment.ToString());
You need to build the child categories one by one.
Hope this was helpful.
Could some please provide me the code to build a category menu in episerver. I have to build a two level category menu. I need to build this from the catalog and not the page structure like the default site.