Tuesday, July 10, 2007

Add image to ASP.Net 2.0 Menu navigation control

To give more beautiful for intranet systems / sites, we may need icons/images to be displayed along with the menu caption.

To map image with a site map node, add a custom property, say, "menuImage" in the sitemapnode tag as below


<siteMapNode url="~/pages/wemployee.aspx" title=":: Employees" description="" menuImage="~/Images/viewdetail.gif" />

Now, in the code behind, add the code below:-

protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
e.Item.ImageUrl = ((SiteMapNode)e.Item.DataItem)["menuImage"];
}

Infact, you can have a harcoded image path as well.

HTH
-::-

No comments: