gpt4 book ai didi

c# - 在 asp :Menu 中将父项和子项都设置为 "Selected"

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:36 25 4
gpt4 key购买 nike

所以我正在尝试执行以下操作,以便为选定的子项及其父项设置样式(StaticSelectedStyle-CssClass 和 DynamicSelectedStyle-CssClass)。以下代码仅使父级设置样式:

  private bool SetSelectedMenuItem(MenuItemCollection menuItems)
{
foreach (MenuItem item in menuItems)
{
string url = ResolveUrl(item.NavigateUrl);
string pageUrl = Request.RawUrl;
if (pageUrl.Equals(url))
{
item.Selected = true;

if (item.Parent != null)
{
item.Parent.Selected = true;
}
return true;
}

if (SetSelectedMenuItem(item.ChildItems))
{
return true;
}
}
return false;
}

是否有可能将子项及其父项的选定值设置为 true?

如果有任何帮助可以让这项工作顺利进行,那就太好了!

最佳答案

这是不可能的。看看documentation on the Selected property .备注部分的最后一行是这样说的:

Only one menu item can be selected at a time in the Menu control.

关于c# - 在 asp :Menu 中将父项和子项都设置为 "Selected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42933795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com