隐藏地图ASP.NET节点TreeView控件 [英] Hiding ASP.NET SiteMap nodes in TreeView control
本文介绍了隐藏地图ASP.NET节点TreeView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的所有节点的地图。我使用的链接到网站地图导航TreeView控件。现在,我想从出现在树视图隐藏某些节点。是否有可能做到这一点?
I have a SiteMap with All my nodes. I'm using a TreeView control which is linked to the SiteMap for navigation. Now I would like to hide certain nodes from appearing on the TreeView. Is it possible to do this?
推荐答案
是的,这是绝对有可能。我们做的方式,它是一个自定义的IsPhantom属性添加到网站地图所示,我们不希望节点(以及各种其他地方也是如此):
Yes, it's definitely possible. The way we do it is to add a custom "IsPhantom" attribute to the nodes we don't want shown in the sitemap (and in various other places too):
<siteMapNode url="~/Welcome.aspx" title="Welcome" description="" isPhantom="true" />
然后在网站地图控制,请使用以下code,除去具有IsPhantom属性节点:
Then in the sitemap control, use the following code to remove nodes that have the "IsPhantom" attribute:
protected void Page_Load(object sender, EventArgs e)
{
TreeView1.TreeNodeDataBound += new TreeNodeEventHandler(TreeView1_TreeNodeDataBound);
SiteMapSource.Provider = this.CurrentProvider;
}
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
SiteMapNode thisMapNode = (SiteMapNode)e.Node.DataItem;
TreeNode parentTreeNode = e.Node.Parent;
if (thisMapNode["isPhantom"] != null && thisMapNode["isPhantom"].ToLower().Equals(bool.TrueString.ToLower()) && parentTreeNode != null)
parentTreeNode.ChildNodes.Remove(e.Node);
}
这篇关于隐藏地图ASP.NET节点TreeView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文