Dec 21, 2008

Menu With Images in web.sitemap

In this we can bind a menu control with web.sitemap file, which contains image url for the images .We can also set the navigation position(i.e. in a new browser or in same browser). Example: I want to make menu in which some items navigates to pages in same browser and some open .pdf or .doc file in new browser.
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal"

StaticDisplayLevels="2" DynamicHorizontalOffset="2" DynamicVerticalOffset="5"

ForeColor="White" StaticSubMenuIndent="0px" StaticEnableDefaultPopOutImage="false"

OnMenuItemDataBound="Menu1_MenuItemDataBound" Target="_self">

<StaticSelectedStyle BackColor="#0A7D92" />

<StaticMenuItemStyle VerticalPadding="2px" ItemSpacing="0px" />

<%----%>

<DynamicMenuStyle BackColor="#0A7D92" BorderWidth="1" BorderColor="Black" CssClass="tdInput" />

<DynamicSelectedStyle BackColor="#FFCC66" />

<DynamicMenuItemStyle HorizontalPadding="5px" />

asp:Menu>

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" SiteMapProvider="Connectors" />

protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)

{

MenuItem item = (MenuItem)e.Item;

if (e.Item.Depth == 1 || e.Item.Depth == 0)

{

// Reference the underlying SiteMapNode object...

SiteMapNode nodeFromSiteMap = (SiteMapNode)e.Item.DataItem;

item.NavigateUrl = nodeFromSiteMap.Url;

item.ImageUrl = nodeFromSiteMap["imageUrl"];

item.Text = "";

}

else

{

item.Target = "_blank";

}

}

In web.sitemap add the nodes <siteMapNode url="GPConnectors.aspx" title="Connectors" imageUrl="MenuImages/Connectors.jpg" description="" />






0 comments: