XmlDataSource – Treeview databind based on Parent – Child xml file

Do you need to implement an ASP:TreeView in you website based on a xml file with a nice nested Parent – Child structure? I think that everyone already wrote, at least one time in his life, a recursive function to accomplish this but this can be better 🙂

I found a very good post on this matter: http://www.4guysfromrolla.com/articles/042308-1.aspx

I wasn’t aware of this solution, so I learned something! 🙂

ASPX Page:



<Node title=”France”>
<Node title=”Paris”>
<FieldRef title=”Population” value=”2,211,297″/>
<Node title=”Belgium”>
<Node title=”Antwerp”>
<FieldRef title=”Population” value=”507,050″/>
<Node title=”Brussel”>
<FieldRef title=”Population” value=”1,800,000″/>

Code-Behind (the xml-file is located in SharePoint ;-))

using (SPWeb spWeb = SPContext.Current.Site.OpenWeb(“KB”))
SPFile spFile = spWeb.GetFile(“/kb/Templates/DocDetail_TreeFile.xml”);
StreamReader reader = new StreamReader(spFile.OpenBinaryStream());
xmlData.Data = reader.ReadToEnd();

This entry was posted in Geen categorie and tagged . Bookmark the permalink.

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