I had to do something similar and found this post. I was going to implement my own control and thought about our good old friend - recursion. It's already being use in CreateChildMenu, but only to populate the selected Category.
Therefore, my simple solution was to modify the signature of CreateChildMenu to include a boolean parameter (at the end): true - bring back all Categories; false - brind back only the selected (clicked) Category and its children. Note. I recommend you set the boolean parameter from a setting stored in the db.
Modified CreateChildMenu call to include true\false setting, e.g. CreateChildMenu(breadCrumb, 0, currentCategory, true);
CreateChildMenu
Modified signature to:
protected void CreateChildMenu(CategoryCollection breadCrumb, int rootCategoryID, Category currentCategory, int level, bool showAllCategories)
Wrapped up 'for' loop:
if (showAllCategories) { // Show All Categories and their children CreateChildMenu(breadCrumb, category.CategoryID, currentCategory, level,showAllCategories); } else { // Show only Selected Category children for (int i = 0; i <= breadCrumb.Count - 1; i++) if (breadCrumb[i].CategoryID == category.CategoryID) CreateChildMenu(breadCrumb, category.CategoryID, currentCategory, level, showAllCategories); }
That was an easy fix - too easy? I hope it helps someone.
Therefore, my simple solution was to modify the signature of CreateChildMenu to include a boolean parameter (at the end): true .....................That was an easy fix - too easy? I hope it helps someone.
Webie, I was looking for this fot a entire month. Thank you so much!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.