在线急等,menu控件任何隐藏某项的下拉,但别的要求可以显示
如题,谢谢
------解决方案--------------------这段代码就是把 子节点是 "Book 0 " 的节点全部移除了
你要是把:
---------------------
using System.Xml;
using System.Xml.XPath;
.....
XmlDocument xmlDoc;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadXmlMenu();
}
}
public void LoadXmlMenu()
{
xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath( "sitemap.xml "));
XmlNodeList xnl = xmlDoc.SelectSingleNode( "siteMap ").ChildNodes;
foreach (XmlNode xn in xnl)
{
XmlElement xe = (XmlElement)xn;
MenuItem miRoot = new MenuItem();
miRoot.Text = xe.GetAttribute( "title ");
miRoot.Value = xe.GetAttribute( "title ");
miRoot.ToolTip = xe.GetAttribute( "description ");
miRoot.NavigateUrl = xe.GetAttribute( "url ");
Menu1.Items.Add(miRoot);
BindXmlMenuItem(xn.ChildNodes,miRoot);
}
}
public void BindXmlMenuItem(XmlNodeList xnl,MenuItem mi)
{
foreach (XmlNode xnNext in xnl)
{
XmlElement xe = (XmlElement)xnNext;
MenuItem miNext = new MenuItem();
miNext.Text = xe.GetAttribute( "title ");
miNext.Value = xe.GetAttribute( "title ");
miNext.ToolTip = xe.GetAttribute( "description ");
miNext.NavigateUrl = xe.GetAttribute( "url ");
mi.ChildItems.Add(miNext);
//if (miNext.Text == "Book 0 ")
//{
// mi.ChildItems.Remove(miNext);
//}
//else
//{
BindXmlMenuItem(xnNext.ChildNodes, miNext);//这段代码留着
//}
}
}
//这段代码注释掉了 "Book 0 " 节点就显示出来了