C# 站点地图删除节点
我有一个web.sitemap,对于特定情况,我需要从中删除节点C# 站点地图删除节点,c#,asp.net,sitemap,C#,Asp.net,Sitemap,我有一个web.sitemap,对于特定情况,我需要从中删除节点。但我发现SiteMapNode集合是只读异常。有办法吗 <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"> <siteMapNode url="~/default.aspx" title="Home" description=""
。但我发现SiteMapNode集合是只读异常。有办法吗
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNode url="~/default.aspx" title="Home" description="">
<siteMapNode url="~/main.aspx" title="Main" description="">
<siteMapNode url="~/mainv.aspx" title="MainV" description="">
<siteMapNode url="~/last.aspx" title="Last" description="">
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
编辑:
protected void SiteMapPath1_ItemDataBound(object sender, SiteMapNodeItemEventArgs e)
{
SiteMapNodeCollection modifiableCollection = new SiteMapNodeCollection(e.Item.SiteMapNode.RootNode.ChildNodes);
modifiableCollection.RemoveAt(2);
}
现在我发现索引超出了范围。必须为非负且小于集合的大小。\r\n参数名称:index因为sitemapcollection是只读的,解决方法是创建一个要绑定的新sitemapcollection,这不包含不需要的条目。@Furqan我尝试了siteMapCollection,但找不到要删除的元素亲爱的使用现有siteMapCollection创建一个新的SiteCollectionMap对象,然后绑定NewsMap。你能试试吗?也许有用,你说我尝试了siteMapCollection,但找不到要删除的元素,你能把你试过的代码放进去吗?
protected void SiteMapPath1_ItemDataBound(object sender, SiteMapNodeItemEventArgs e)
{
SiteMapNodeCollection modifiableCollection = new SiteMapNodeCollection(e.Item.SiteMapNode.RootNode.ChildNodes);
modifiableCollection.RemoveAt(2);
}