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
vivek_cool 17-Aug-11 1:51am
please mention your question brifly... its not clearly describe what u through hard coded or javascript

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

xml file-


<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 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" />




Now use this code to design menu using xml.

private void CreateMenuWithXmlFile()


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

DataSet ds = new DataSet();


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);


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


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


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


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








follow this link also-

Hope this will help you.
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:

Security Trimming Info:

SiteMap Binding Info:

Good Tutorial/Overview here:

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:

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