Hide Root Node of XML Bound TreeView (ASP.NET)



Please visit http://suanaikyeo.com instead

You have a treeview with an XML file as a data source, but XML files by default must have a single root element, which shows up on your treeview. A lot of us don’t want it to show up, and there’s no obvious way to hide it. After an hour or so of searching for a solution, I found it here. This solution really needs to be more visible on the web!

Basically you just need to set the XMLDataSource XPath property as XPath = “/*/*”. I’m not entirely sure what this means, but you can read up more about it here.


Tags: , , , , , , ,

14 Responses to “Hide Root Node of XML Bound TreeView (ASP.NET)”

  1. Jeff Says:

    Simple. Effective. Exactly what I wanted. This needs to be higher on the Google search result list.

  2. sayeo87 Says:

    Thanks, Jeff, yours is the first real comment I’ve gotten on my blog! And I know exactly what you mean, this solution should be all over the web, but instead it’s buried like 3-4 pages deep in Google!

  3. Jeff Says:

    I just linked to you, so maybe eventually it will make it up the list šŸ™‚

  4. William Says:

    This is the best solution I found. Microsoft should publish and make clear the solultions to common problems in the MSDN documentation.

  5. chidge Says:

    Thanks for this, I understand it, but would never have come up with it. It should be one of the first things covered when discussing XML Tree View links in any training material.

  6. Cliff Says:


  7. Hari Says:


  8. BerryC Says:

    I can’t believe something *THIS* simple is so hard to find!

    It came up as the 2nd google hit when searching for “asp.net treeview hide root”.
    Usually people will click the first hit (like me) thinking it will have the best answer. OMG, the first hit has TONS of code just to hide the root node! Of course, that solution doesn’t use XMLDataSource, so, maybe for that solution it is necessary (e.g. SQLDataSource). In any case, that first solution should merely write out the SQL data to XML, then use XMLDataSource for the treeview’s XPath!
    I’m gonna put this solution on that question’s comment area!

  9. Ruchi Says:

    Amazing… Thanks a lot it saved my hell lot of time šŸ™‚

  10. Rupsesh Bari Says:

    Thanks a lot friend..

  11. Beeza Says:

    Thank you very very much. This helped me a lot.

  12. Bryce Says:

    Fantastic site. Plenty of useful info here. I am sending it to some friends ans also sharing in delicious. And certainly, thanks for your sweat!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: