Click here to Skip to main content
15,077,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

In my website i am displaying menu by including master pages ,now i want to change the menus according to login change ,how can i do that

Ankita mali
Posted
Comments
vivek_cool 17-Aug-11 1:51am
   
please mention your question brifly... its not clearly describe what u want..you through hard coded or javascript

Follow this example , here i am creating menu using xml file.

xml file-



<sitemap>

<sitemapnode url="Default.aspx" title="Home">

<sitemapnode title="Products" description="Our Products">

<sitemapnode url="Product1.aspx" title="My Products">

description="These are my products" />

<sitemapnode url="Product2.aspx" title="New Products">

description="Some new products " />

</sitemapnode>

<sitemapnode title="Services" description="Our Services">

<sitemapnode url="Service1.aspx" title="ASP.NET Consulting">

description="Best ASP.NET Consulting" />

<sitemapnode url="Service2.aspx" title="ASP.NET Training">

description="Best ASP.NET Training" />

</sitemapnode>

</sitemapnode>

</sitemapnode></sitemapnode></sitemapnode></sitemapnode></sitemap>


Now use this code to design menu using xml.

private void CreateMenuWithXmlFile()

{

string path = @"C:\MyXmlFile.xml";

DataSet ds = new DataSet();

ds.ReadXml(path);

Menu menu = new Menu();

menu.MenuItemClick += new MenuEventHandler(menu_MenuItemClick);

for (int i = 0; i < ds.Tables.Count; i++)

{

MenuItem parentItem = new MenuItem((string)ds.Tables[i].TableName);

menu.Items.Add(parentItem);

for (int c = 0; c < ds.Tables[i].Columns.Count; c++)

{

MenuItem column = new MenuItem((string)ds.Tables[i].Columns[c].ColumnName);

menu.Items.Add(column);

for (int r = 0; r < ds.Tables[i].Rows.Count; r++)

{

MenuItem row = new MenuItem((string)ds.Tables[i].Rows[r][c].ToString());

parentItem.ChildItems.Add(row);

}

}

}

Panel1.Controls.Add(menu);

Panel1.DataBind();

}


follow this link also-

http://www.codeproject.com/KB/menus/PopulatingMenuControlASP2.aspx

Hope this will help you.
   
v2
Comments
nagendrathecoder 17-Aug-11 2:47am
   
Format your code snippet properly.
vivek_cool 17-Aug-11 3:02am
   
how you you want answer in proper format... you should aware only with answer na why you need format
You can bind the menu items to a site map and use the roles attribute. You will need to enable Security Trimming in your Web.Config to do this. This is the simplest way.

Site Navigation Overview: http://msdn.microsoft.com/en-us/library/e468hxky.aspx


Security Trimming Info: http://msdn.microsoft.com/en-us/library/ms178428.aspx


SiteMap Binding Info: http://www.w3schools.com/aspnet/aspnet_navigation.asp


Good Tutorial/Overview here:

http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and-security-don-t-match-up.aspx


Another option that works, but is less ideal is to use the loginview control which can display controls based on role. This might be the quickest (but least flexible/performant) option. You can find a guide here:

http://weblogs.asp.net/sukumarraju/archive/2010/07/28/role-based-authorization-using-loginview-control.aspx
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900