RadMenu 隐藏子菜单
RadMenu hide submenu
我正在使用单选菜单。我喜欢隐藏子菜单项。
菜单如下所示。请注意,Car 是主菜单,Dodge、Toyota 和 Honda 是子菜单。
汽车
- 闪避
- 丰田
- 本田
我正在尝试执行类似以下操作但行不通:
protected void RadMenu1_ItemCreated(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
if (e.Item is RadMenuItem)
{
if (e.Item.Parent != null && e.Item.Parent is RadMenuItem)
{
if (e.Item.Menu.FindItemByText("Honda"))
{
e.Item.Visible = false;
}
}
}
}
请尝试使用以下代码片段,如有任何疑问,请告诉我。
ASPX
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<telerik:RadMenu ID="RadMenu1" runat="server" OnPreRender="RadMenu1_PreRender">
<Items>
<telerik:RadMenuItem Text="cars">
<Items>
<telerik:RadMenuItem Text="Honda"></telerik:RadMenuItem>
<telerik:RadMenuItem Text="Toyota"></telerik:RadMenuItem>
</Items>
</telerik:RadMenuItem>
</Items>
</telerik:RadMenu>
</div>
ASPX.CS
protected void RadMenu1_PreRender(object sender, EventArgs e)
{
foreach (RadMenuItem item in (sender as RadMenu).Items)
{
if (item.Items.Count > 0)
{
foreach (RadMenuItem citem in item.Items)
{
if (citem.Text != "Honda")
{
citem.Visible = false;
}
}
}
}
}
// Hide top menu cars
protected void RadMenu1_PreRender(object sender, EventArgs e)
{
foreach (RadMenuItem item in (sender as RadMenu).Items)
{
if (item.Items.Count > 0)
{
if(item.Text == "cars")
{
item.Visible = false;
}
foreach (RadMenuItem citem in item.Items)
{
if (citem.Text != "Honda")
{
citem.Visible = false;
}
}
}
}
}
我正在使用单选菜单。我喜欢隐藏子菜单项。
菜单如下所示。请注意,Car 是主菜单,Dodge、Toyota 和 Honda 是子菜单。
汽车 - 闪避 - 丰田 - 本田
我正在尝试执行类似以下操作但行不通:
protected void RadMenu1_ItemCreated(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
if (e.Item is RadMenuItem)
{
if (e.Item.Parent != null && e.Item.Parent is RadMenuItem)
{
if (e.Item.Menu.FindItemByText("Honda"))
{
e.Item.Visible = false;
}
}
}
}
请尝试使用以下代码片段,如有任何疑问,请告诉我。
ASPX
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<telerik:RadMenu ID="RadMenu1" runat="server" OnPreRender="RadMenu1_PreRender">
<Items>
<telerik:RadMenuItem Text="cars">
<Items>
<telerik:RadMenuItem Text="Honda"></telerik:RadMenuItem>
<telerik:RadMenuItem Text="Toyota"></telerik:RadMenuItem>
</Items>
</telerik:RadMenuItem>
</Items>
</telerik:RadMenu>
</div>
ASPX.CS
protected void RadMenu1_PreRender(object sender, EventArgs e)
{
foreach (RadMenuItem item in (sender as RadMenu).Items)
{
if (item.Items.Count > 0)
{
foreach (RadMenuItem citem in item.Items)
{
if (citem.Text != "Honda")
{
citem.Visible = false;
}
}
}
}
}
// Hide top menu cars
protected void RadMenu1_PreRender(object sender, EventArgs e)
{
foreach (RadMenuItem item in (sender as RadMenu).Items)
{
if (item.Items.Count > 0)
{
if(item.Text == "cars")
{
item.Visible = false;
}
foreach (RadMenuItem citem in item.Items)
{
if (citem.Text != "Honda")
{
citem.Visible = false;
}
}
}
}
}