请尝试使用下面的代码片段,如果有任何问题,请告诉我。
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;
}
}
}
}
}