SiteMapNodeInfo

May 23, 2008 at 5:51 PM
Has anyone been able to instead of text add the URL of the images for the menu item?

code:

SiteMapNodeInfo

moduleNode = new SiteMapNodeInfo("Tasks", "~/", "Tasks");

 

attributes[

"imageName"] = "~/images/Menu/Tasks.png";

 

moduleNode.Attributes.Add(attributes);

siteMapBuilderService.AddNode(moduleNode);

In some sort of fashion that resembles this?

May 26, 2008 at 4:15 PM
Edited May 26, 2008 at 4:19 PM

add

attributes["ImageUrl"]="Url"

to SiteMapNodeInfo

then

In the menu item data bind event, call

        private static void AddImage(MenuEventArgs e)
        {
            SiteMapNode node = e.Item.DataItem as SiteMapNode;
            if (node != null && node["ImageUrl"] != null) e.Item.ImageUrl = node["ImageUrl"];
        }
the size of image is controlled by CSS

.menuitem img
{
    widith:16px;
    height: 16px;
}


Chester in Calgary

May 27, 2008 at 2:31 PM
The problem is this.  I create my sitemapnodeinfo item via  this syntax:

SiteMapNodeInfo

moduleNode = new SiteMapNodeInfo("Tasks", "", "Tasks");

 


But when I runt this code on the very next line I get a NULL Reference exception.

moduleNode.Attributes[

"ImageUrl"] = "./images/tasks.png";

 


Any idea why?

Chesteryang wrote:

add

attributes["ImageUrl"]="Url"

to SiteMapNodeInfo

then

In the menu item data bind event, call

        private static void AddImage(MenuEventArgs e)
        {
            SiteMapNode node = e.Item.DataItem as SiteMapNode;
            if (node != null && node["ImageUrl"] != null) e.Item.ImageUrl = node["ImageUrl"];
        }
the size of image is controlled by CSS

.menuitem img
{
    widith:16px;
    height: 16px;
}


Chester in Calgary


T

May 27, 2008 at 5:57 PM
Edited May 27, 2008 at 6:11 PM
You have to send a NameValueCollection into it when you create the node like this

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Tasks", "", "Tasks", null, new NameValueCollection(), null, null );

I guess that your constructor called the above constructor like this

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Tasks", "", "Tasks", null, null, null, null);

So you get null exception.


I did it like this

       private static NameValueCollection CreateImageUrlAttributes(string imageUrl)
        {
            NameValueCollection attributes = new NameValueCollection(1);
            attributes.Add("ImageUrl", imageUrl);
            return attributes;
        }

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Tasks", "", "Tasks", null, CreateImageUrlAttributes("/images/tasks.png") , null, null );



Chester in Calgary
May 27, 2008 at 8:41 PM


Chesteryang wrote:
You have to send a NameValueCollection into it when you create the node like this

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Tasks", "", "Tasks", null, new NameValueCollection(), null, null );

I guess that your constructor called the above constructor like this

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Tasks", "", "Tasks", null, null, null, null);

So you get null exception.

 


I did it like this

       private static NameValueCollection CreateImageUrlAttributes(string imageUrl)
        {
            NameValueCollection attributes = new NameValueCollection(1);
            attributes.Add("ImageUrl", imageUrl);
            return attributes;
        }

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Tasks", "", "Tasks", null, CreateImageUrlAttributes("/images/tasks.png") , null, null );



Chester in Calgary



Worked like a charm!  Thanks for you help!!