Sara Chipps
Sara Chipps

Reputation: 9372

asp:SiteMapPath with dynamic images

Ok, so I'm building bread crumbs and depending on the value of the breadcrumb an image will be the seperator. So "HOME" will have one image and "SEARCH" will have another.

I know I can do this programatically (at least I ASSUME) but is there an easier way to do this? Can I link an image to a node based on the value of the node? Can I do it with PathSeparatorTemplate?

Thank you.

Upvotes: 1

Views: 1819

Answers (2)

Alfred B. Thordarson
Alfred B. Thordarson

Reputation: 4470

I see you have already accepted an answer, but I thought some code would help, so here is some:

Site1.Master


    <asp:SiteMapPath ID="SiteMapPath1" Runat="server" OnItemDataBound="Item_Bound">
        <PathSeparatorTemplate>
            <asp:Image ID="SepImage" runat="server" ImageUrl="/images"/>
        </PathSeparatorTemplate>
    </asp:SiteMapPath>

Site1.Master.cs


    private string lastItemKey = "";
    public void Item_Bound(Object sender, SiteMapNodeItemEventArgs e)
    {
        if (e.Item.ItemType == SiteMapNodeItemType.PathSeparator)
        {
            string imageUrl = ((Image) e.Item.Controls[1]).ImageUrl;
            imageUrl += lastItemKey + ".png";
            ((Image) e.Item.Controls[1]).ImageUrl = imageUrl;
        }
        else
        {
            lastItemKey = e.Item.SiteMapNode.Key;
        }
    }

Then I have an /images directory containing an image for each of the Key's of the SiteMapNodes. In other terms: this code will result in the image being displayed, after each of the path nodes, to depend on the key of the node before it.

Hope this helps someone.

Upvotes: 0

Aleris
Aleris

Reputation: 8069

You can put an

<asp:Image ... />

into the PathSerparatorTemplate but you still have to set the image url from code.

Upvotes: 2

Related Questions