Asp Menu with SiteMapDataSource

<asp:Menu runat=”server” ID=”mnuMain” OnMenuItemDataBound=”mnuMain_MenuItemDataBound” 
DataSourceID=”SiteMapDataSource1″ MaximumDynamicDisplayLevels=”0″ Orientation=”Horizontal”> 
  <StaticItemTemplate> 
    <table style=”text-align: center”> 
      <tr> 
        <td style=”width: 80px; padding-top: 4px;”> 
               <asp:LinkButton ID=”imgBtnCustomer” runat=”server” ToolTip=’<%# Eval(“ToolTip”).ToString() %> 
                    PostBackUrl=’<%# Eval(“NavigateUrl”).ToString() %> Width=”80px”> 
                <asp:Image runat=”server” ID=”imgCustomer” Height=”50px” /> 
             </asp:LinkButton></td>
<td style=”width: 3px;”>
<asp:Image ID=”imgSep1″ runat=”server” ImageUrl=’<%# AdminTool.Code.CommonValues.ImagePath(“separator.gif”)%> /></td>
</tr></table></StaticItemTemplate></asp:Menu> 
<asp:SiteMapDataSource ID=”SiteMapDataSource1″ runat=”server” ShowStartingNode=”False” />

——

<?xml version=1.0 encoding=utf-8?>
<siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0 enableLocalization=true>
<siteMapNode url=~/Home.aspx title=“” description=“” roles=DealerAdmin,DealerUser,CustomerAdmin>
<siteMapNode url=~/Customers.aspx title=Customers description=Customers ImageSrc=butTimeCard.gif ImageHoverSrc=butTimeCardOver.gif ToolTip=Customers resourceKey=Customers roles=DealerAdmin,DealerUser>
<siteMapNode url=~/EditCustomer.aspx title=Edit customer description=Edit customer ImageSrc=butTimeCard.gif ImageHoverSrc=butTimeCardOver.gif resourceKey=EditCustomer roles=DealerAdmin,DealerUser/>
<siteMapNode url=~/EditCustomerContact.aspx title=Edit customer contact description=Edit customer contact ImageSrc=butTimeCard.gif ImageHoverSrc=butTimeCardOver.gif resourceKey=EditContact roles=DealerAdmin,DealerUser/>
<siteMapNode url=~/EditTerminal.aspx title=Edit terminal info description=Edit terminal info ImageSrc=butTimeCard.gif ImageHoverSrc=butTimeCardOver.gif resourceKey=EditTerminal roles=DealerAdmin,DealerUser/>
<siteMapNode url=~/LinkEmployees.aspx title=Link Employees description=Link Employees ImageSrc=butTimeCard.gif ImageHoverSrc=butTimeCardOver.gif resourceKey=LinkEmployee roles=DealerAdmin,DealerUser/>
<siteMapNode url=~/ErrorReportDisplay.aspx title=ErrorReport description=ErrorReport ImageSrc=butTimeCard.gif ImageHoverSrc=butTimeCardOver.gif resourceKey=ErrorReport roles=DealerAdmin,DealerUser/>
<siteMapNode url=~/LoginPopup.aspx title=Login popup description=Login popup roles=DealerAdmin,DealerUser/>
</siteMapNode>
<siteMapNode url=~/Reports.aspx title=Reports description=Reports resourceKey=Reports ImageSrc=butReport.gif ImageHoverSrc=butReportOver.gif ToolTip=Reports roles=DealerAdmin>
<siteMapNode url=~/BillingExport.aspx title=Billing Export description=BillingExport resourceKey=BillingExport roles=DealerAdmin/>
</siteMapNode>
<siteMapNode url=~/ConfigMain.aspx title=Configuration description=Configuration resourceKey=Config ImageSrc=butConfiguration.gif ImageHoverSrc=butConfigurationOver.gif ToolTip=Configuration roles=DealerAdmin,DealerUser,CustomerAdmin >
<siteMapNode url=~/ChangePassword.aspx title=Change Password description=ChangePassword resourceKey=ChangePassword ImageSrc=butConfiguration.gif ImageHoverSrc=butConfigurationOver.gif roles=DealerAdmin,DealerUser,CustomerAdmin />
<siteMapNode url=~/Users.aspx title=Users description=Users resourceKey=Users ImageSrc=butConfiguration.gif ImageHoverSrc=butConfigurationOver.gif roles=DealerAdmin,CustomerAdmin >
<siteMapNode url=~/EditUser.aspx title=Edit user description=Edit user resourceKey=EditUser ImageSrc=butConfiguration.gif ImageHoverSrc=butConfigurationOver.gif roles=DealerAdmin,CustomerAdmin/>
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
—–
 protected void mnuMain_MenuItemDataBound(object sender, MenuEventArgs e) {
int i = 0; 
MenuItem item = e.Item as MenuItem; 
if (item != null) { 
SiteMapNode node = item.DataItem as SiteMapNode;
item.ToolTip = node[“ToolTip”];
item.ImageUrl = node[“ImageSrc”];
item.Value = node[“ImageHoverSrc”];
item.NavigateUrl = node.Url;
}
}
—-

protected override void Render(HtmlTextWriterwriter) {  
int i = 0;  
foreach (MenuItem item in mnuMain.Items) {  
Image imgCustomer = mnuMain.Controls[i].Controls[0].FindControl(“imgCustomer”) as Image;

imgCustomer.ImageUrl = CommonValues.ImagePath(item.ImageUrl);imgCustomer.ToolTip = item.ToolTip;

imgCustomer.Attributes.Add(“onmouseover”, “src='” + CommonValues.ImagePath(item.Value) + “‘”);

imgCustomer.Attributes.Add(“onmouseout”, “src='” + CommonValues.ImagePath(item.ImageUrl) + “‘”);

i++;} 
base.Render(writer);}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s