Category Navigation & Expanding all nodes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 years ago
Hi all,

Is there a way to configure/mod the left nav category control/code to ALWAYS expand to show sub categories?

Regards,
   Rock
14 years ago
No not out of the box.  You will need write some custom code to complete this.  

A quick and dirty way is to use a asp.net treeview control.

Thanks,
Matthew
14 years ago
Thanks Matthew!

Customization it is then I guess...

- rock
14 years ago
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.

Here's the solution:

Path: Modules
Control: CategoryNavigation.ascx
Code File: CategoryNavigation.ascx.cs

Methods changed:

CreateMenu

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.
14 years ago
not woking for me i need more help if you can
thank you
14 years ago
Hi,

What is the problem/error that you are receiving? If you post a snippet of your code then that would help.

Cheers
13 years ago
Thanks webie, the code works for me. Thank you.

put the code the webie provided after the below code in file then it should work.

link.HyperLink.Text = Server.HtmlEncode(catName);
if (padding > 0)
  link.LiLeftMargin = padding.ToString();

Thanks again webie.
13 years ago
Thank you Webie for posting this.  I was able to add it to my code, tweak it a little and it worked just fine.

Thanks again, Steffany
13 years ago
with2fs wrote:
Thank you Webie for posting this.  I was able to add it to my code, tweak it a little and it worked just fine.

Thanks again, Steffany


can you plz share the complete code here ?
13 years ago
webie wrote:
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.