Databinding XML to a TreeView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QnJpYW4gTmljaG9sc29u?=

    Databinding XML to a TreeView

    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.DataSou rce = xmlds
    treeSrc.DataBin d()

    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.
  • =?Utf-8?B?TWFuaXNo?=

    #2
    RE: Databinding XML to a TreeView

    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:C1WebBindi ng DataMember="cha nnels" Text="channels" ></c1c:C1WebBindin g>
    <c1c:C1WebBindi ng DataMember="cha nnel" TextField="id"> </c1c:C1WebBindin g>
    <c1c:C1WebBindi ng DataMember="mes sage" ToolTipField="c omment"
    NavigateUrlFiel d="link" TextField="titl e"></c1c:C1WebBindin g>

    Regards,
    Manish
    MESCIUS USA Inc. has JavaScript and .NET UI controls, datagrids, reporting solutions, spreadsheets, document APIs and more to take your applications further.


    "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.DataSou rce = xmlds
    treeSrc.DataBin d()
    >
    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.

    Comment

    • =?Utf-8?B?QnJpYW4gTmljaG9sc29u?=

      #3
      RE: Databinding XML to a TreeView

      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:C1WebBindi ng DataMember="cha nnels" Text="channels" ></c1c:C1WebBindin g>
      <c1c:C1WebBindi ng DataMember="cha nnel" TextField="id"> </c1c:C1WebBindin g>
      <c1c:C1WebBindi ng DataMember="mes sage" ToolTipField="c omment"
      NavigateUrlFiel d="link" TextField="titl e"></c1c:C1WebBindin g>
      >
      Regards,
      Manish
      www.ComponentOne.com

      Comment

      Working...