开发者

Dynamically set NavigateUrl for a menu item in asp.net c#

开发者 https://www.devze.com 2023-03-03 09:30 出处:网络
I try to reach classic navigation menu item from website in c#, asp.net. My navigation menu like that:

I try to reach classic navigation menu item from website in c#, asp.net. My navigation menu like that :

Dynamically set NavigateUrl for a menu item in asp.net c#

How can I reach My Profile NavigateURL and change it? I tried this but mi is null:

Menu m = (Menu)Master.FindControl("NavigationMenu");
MenuItem mi = new MenuItem();
mi = m.FindItem("Account,My Profile"); 
mi.NavigateUrl = "~/MyProfile.aspx?u开发者_运维知识库serid=" + userid;

Please help :(


This should work:

var menu = (Menu)Master.FindControl("NavigationMenu");
var menuItem = menu.FindItem("Account" + menu.PathSeparator + "My Profile");
menuItem.NavigateUrl = "~/MyProfile.aspx?userid=" + 123;

The default PathSeparator is a slash mark (/).

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.pathseparator.aspx

If you didn't override it, then you can also use path Account/My Profile

0

精彩评论

暂无评论...
验证码 换一张
取 消