Databinding XML to a TreeView

Discussion in 'ASP .Net' started by Brian Nicholson, Jul 9, 2008.

  1. 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.
    Brian Nicholson, Jul 9, 2008
    #1
    1. Advertising

  2. Brian Nicholson

    Manish Guest

    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

    "Brian Nicholson" wrote:

    > 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.
    Manish, Jul 10, 2008
    #2
    1. Advertising

  3. 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?

    "Manish" wrote:

    > 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
    Brian Nicholson, Jul 10, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex D.

    Databinding Treeview to XML

    Alex D., Jun 5, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    311
    Alex D.
    Jun 5, 2006
  2. Alex D.

    Databinding Treeview to XML??

    Alex D., Jun 6, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    409
    Alex D.
    Jun 6, 2006
  3. Alex D.

    Databinding Treeview to XML????

    Alex D., Jun 6, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    337
    Alex D.
    Jun 6, 2006
  4. jobs
    Replies:
    0
    Views:
    1,589
  5. Earl Teigrob
    Replies:
    1
    Views:
    385
    Shravan
    Mar 1, 2004
Loading...

Share This Page