SiteMapNodeInfo CSS

Topics: Web Client Software Factory
Apr 25, 2007 at 2:30 PM
Hi,

I was wondering, is it possible for me to specify my own "id" or "class" in the sitemap generated by the SiteMap provider? I tried TreeView and SiteMap providers, and both can't seem to accomodate my needs. I want to apply my own css style to each of sitemap node, so I would really like to have their id specified by me, instead of automatically generated.

Another thing, SiteMapNodeInfo has property called Attributes, anyone knows about this? At first I thought that it can be used to accomodate the case I described above, but it doesn't seem to do anything.

Thanks in advance
Coordinator
Apr 25, 2007 at 4:43 PM
Hi SorCeRer,
This is a limitation of the Menu provided by ASP.NET… you cannot specify a different class or id to each MenuItem, and as you said, this is automatically generated. What you can do is specify a style to the currently selected menu item, and a different one for the rest; this is done in the Menu control.

On the other hand, the Attributes property of SideMapNodeInfo is automatically copied to the SiteMapNode when the SiteMap is built, but as you already know, the Menu does not use this attributes to apply style. Here is a code snippet of the Master page of the GlobalBank Reference Implementation solution that uses attributes (you can check the ModuleInitializer classes to see how these are set):
    protected void ModulesMenu_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        SiteMapNode siteMapNode = (SiteMapNode)e.Item.DataItem;
 
        string pathStringFormat = IsModuleActive(siteMapNode) ? ConfigurationManager.AppSettings["ModuleImagePathFormatString_Active"] :
                                                         ConfigurationManager.AppSettings["ModuleImagePathFormatString_Inactive"];
        e.Item.ImageUrl = String.Format(pathStringFormat, siteMapNode["imageName"]);
    }

There you can see how the imageName attribute is (manually) used to set the ImageUrl of the MenuItem.

I hope this helps a bit to clarify things,
Julián Domínguez
http://staff.southworks.net/blogs/jdominguez