<p>I've got a Repeater that lists all the <code>web.sitemap</code> child pages on an ASP.NET page.  Its <code>DataSource</code> is a <code>SiteMapNodeCollection</code>.  But, I don't want my registration form page to show up there.</p>

<pre><code>Dim Children As SiteMapNodeCollection = SiteMap.CurrentNode.ChildNodes

'remove registration page from collection
For Each n As SiteMapNode In SiteMap.CurrentNode.ChildNodes
If n.Url = "/Registration.aspx" Then
    Children.Remove(n)
End If
Next

RepeaterSubordinatePages.DataSource = Children
</code></pre>

<p>The <code>SiteMapNodeCollection.Remove()</code> method throws a </p>

<blockquote>
  <p>NotSupportedException: "Collection is read-only".</p>
</blockquote>

<p>How can I remove the node from the collection before DataBinding the Repeater?</p>

[{'answer_id': 12303, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 1, 'selected': False, 'text': '<p>Using Linq and .Net 3.5:</p>\n\n<pre><code>//this will now be an enumeration, rather than a read only collection\nDim children = SiteMap.CurrentNode.ChildNodes.Where( _\n    Function (x) x.Url &lt;&gt; "/Registration.aspx" )\n\nRepeaterSubordinatePages.DataSource = children \n</code></pre>\n\n<p>Without Linq, but using .Net 2:</p>\n\n<pre><code>Function IsShown( n as SiteMapNode ) as Boolean\n    Return n.Url &lt;&gt; "/Registration.aspx"\nEnd Function\n\n...\n\n//get a generic list\nDim children as List(Of SiteMapNode) = _\n    New List(Of SiteMapNode) ( SiteMap.CurrentNode.ChildNodes )\n\n//use the generic list\'s FindAll method\nRepeaterSubordinatePages.DataSource = children.FindAll( IsShown )\n</code></pre>\n\n<p>Avoid removing items from collections as that\'s always slow. Unless you\'re going to be looping through multiple times you\'re better off filtering.</p>\n'}, {'answer_id': 12362, 'author': 'Zack Peterson', 'author_id': 83, 'author_profile': 'https://Stackoverflow.com/users/83', 'pm_score': 0, 'selected': False, 'text': '<p>I got it to work with code below:</p>\n\n<pre><code>Dim children = From n In SiteMap.CurrentNode.ChildNodes _\n               Where CType(n, SiteMapNode).Url &lt;&gt; "/Registration.aspx" _\n               Select n\nRepeaterSubordinatePages.DataSource = children\n</code></pre>\n\n<p>Is there a better way where I don\'t have to use the <code>CType()</code>?</p>\n\n<p>Also, this sets children to a <code>System.Collections.Generic.IEnumerable(Of Object)</code>.  Is there a good way to get back something more strongly typed like a <code>System.Collections.Generic.IEnumerable(Of System.Web.SiteMapNode)</code> or even better a <code>System.Web.SiteMapNodeCollection</code>?</p>\n'}, {'answer_id': 12373, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 2, 'selected': True, 'text': '<p>Your shouldn\'t need CType</p>\n\n<pre><code>Dim children = _\n    From n In SiteMap.CurrentNode.ChildNodes.Cast(Of SiteMapNode)() _\n    Where n.Url &lt;&gt; "/Registration.aspx" _\n    Select n\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/12297', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/83/']