动态更改网站的菜单项

动态更改网站的菜单项

本文介绍了动态更改网站的菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

在我的网站上,我正在通过包含母版页来显示菜单,现在我要根据登录更改来更改菜单,我该怎么做

Ankita mali

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

推荐答案

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>



现在,使用此代码通过xml设计菜单.



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

}



跟随此链接也-

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

希望这会对您有所帮助.



follow this link also-

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

Hope this will help you.



这篇关于动态更改网站的菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:03