Databinding XML to a TreeView

  • Thread starter Brian Nicholson
  • Start date
B

Brian Nicholson

Hello -- I'm having problems figuring out how to bind an XML file to a
treeview control. I have the following test XML:

<?xml version="1.0" encoding="utf-8"?>
<instruments>
<instrument name="Name1" type="Type1" path="Path1" />
<instrument name="Name2" type="Type2" path="Path2" />
<instrument name="Name3" type="Type3" path="Path3" />
</instruments>

And I try databinding it to the TreeView with the following:

Dim xmlds As New XmlDataSource()
xmlds.DataFile = Server.MapPath("test.xml")
treeSrc.DataSource = xmlds
treeSrc.DataBind()

The problem is that the items appear in the tree like this:

instruments
instrument
instrument
instrument

But I would instead rather have them appear like this:

Name1 [Type1]
Name2 [Type2]
Name3 [Type3]

I figure I'll have to implement custom data binding, but I can't figure out
how.

Thanks for your help.
 
M

Manish

Hello Brian,

Please try the XMLDataSource control, assign your XML file to this control.
and then bind your treeview with this XML datasource and then do the
Databinding for each node in the treeview something similar to our control.

<c1c:C1WebBinding DataMember="channels" Text="channels"></c1c:C1WebBinding>
<c1c:C1WebBinding DataMember="channel" TextField="id"></c1c:C1WebBinding>
<c1c:C1WebBinding DataMember="message" ToolTipField="comment"
NavigateUrlField="link" TextField="title"></c1c:C1WebBinding>

Regards,
Manish
www.ComponentOne.com
 
B

Brian Nicholson

Thanks; this helped to an extent. I now have the following:

instruments
Name1
Name2
Name3

Each "instrument" node has both a name and a type value -- is there a way to
get both of these to appear simultaneously in the TextField?
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top