How to change the background color or image of each of my category menu link.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
How to change the background color or image of each of  my category link.
First, thanks for sharing this great product.
I would like some of my Category menu  links to have a different background color.

I have added a Placeholder in the CategoryNavigation.aspx

<div>
        <ul class="listbox">
            <asp:PlaceHolder runat="server" ID="phCategories" EnableViewState="false" />
        </ul>
    
        <ul ="listboxeven">
            <asp:PlaceHolder runat="server" ID="phCategorieseven" EnableViewState="false" />
        </ul>
    </div>

And since the links are created dynamically,  I added the following code

                if (category.CategoryId = 5)
                {
                    phCategorieseven.Controls.Add(link);
                    link.BackColor = "Beige";
                  
                }
                else if (category.CategoryId != 5)
                { phCategorie.Controls.Add(link);
                    link.BackColor = "Bisque";
                }

In…..CategoryNavigation.aspx.cs

protected void CreateChildMenu(List<Category> breadCrumb, int rootCategoryId, Category currentCategory, int level)
        {
            int padding = level++ * 15;
            foreach (var category in CategoryManager.GetAllCategoriesByParentCategoryId(rootCategoryId))
            {              

                
                var link = new NopCommerceLi();
                if (category.CategoryId = 5)
                {
                    phCategorieseven.Controls.Add(link);
                    link.BackColor = "Beige";
                  
                }
                else if (category.CategoryId != 5)
                { phCategorie.Controls.Add(link);
                    link.BackColor = "Bisque";
                }

                string categoryURL = SEOHelper.GetCategoryUrl(category);
                
                if (currentCategory != null && currentCategory.CategoryId == category.CategoryId)
                    link.CssClass = "active";
                else
                    link.CssClass = "inactive";
                link.HyperLink.NavigateUrl = categoryURL;
                link.HyperLink.Text = Server.HtmlEncode(category.LocalizedName);
                if (padding > 0)
                    link.LiLeftMargin = padding.ToString();

                for (int i = 0; i <= breadCrumb.Count - 1; i++)
                    if (breadCrumb[i].CategoryId == category.CategoryId)
                        CreateChildMenu(breadCrumb, category.CategoryId, currentCategory, level);
            }
        }
        #endregion
    }
}

But for some reason the variable link.BackColor  never gets any other value then Null. And yes CategoryId 5 exists…

Any suggestions?

Many thanks in advance…

CafeCouleur
13 years ago
Try moving the link.BackColor = "Beige"; line above the phCategorieseven.Controls.Add(link);

SO:

FROM

phCategorieseven.Controls.Add(link);
link.BackColor = "Beige";

TO

link.BackColor = "Beige";
phCategorieseven.Controls.Add(link);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.