[ASP.net 2] TreeView & XmlDocument ?

G

Guest

Hello !

I have an XmlDocument in memory and I want to put this document as
datasource of my treeview.
How to do this ?
Thanks.
 
B

Brock Allen

The TreeView uses a XmlDataSource, so what you need to do is set the XML
into the XmlDataSource. Unfortunately it doesn't accept a XmlReader or a
XmlNode and only allows you to set int a string. But it works.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
G

Guest

Hi !

To do what you said, I do this:
// Simulate the XmlDocument created in memory
XmlDocument xmd = new XmlDocument();
xmd.Load(Server.MapPath("~/test.xml"));

XmlDataSource xds = new XmlDataSource();
xds.Data = xmd.InnerXml;

MyTreeView.DataSource = xds;
MyTreeView.DataBind();

This work, but there is a little problem, in my XML file I have an attribute
called 'Url' and to use this field I have this declaration with my TreeView:
<asp:TreeNodeBinding DataMember="Link" ValueField="ID" TextField="Name"
NavigateUrlField="Url" />

And finally, on the TreeView created, I haven't the link.

I can't understand why I have this problem because if I do that instead of
simulate the XmlDocument in memory:
XmlDataSource xds = new XmlDataSource();
xds.DataFile = Server.MapPath("~/test.xml");

MyTreeView.DataSource = xds;
MyTreeView.DataBind();

This work pretty fine and I have the link.

?_?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top