TreeView - Populating from XML

Populated via the LoadContentFile method

  • DesktopDesktop
    • Administrator
      • AppData
      • Contacts
      • Downloads
      • Documents
      • Favorites
      • Music
      • Pictures
      • Saved Games
      • Searches
      • Videos
    • My ComputerComputer
      • WebServer (\\10.0.0.80) (W:)
      • Local Disk (C:)
        • inetpub
          • AdminScripts

Bound to XmlDataSource

  • Desktop
    • Administrator
      • AppData
      • Contacts
      • Downloads
      • Documents
      • Favorites
      • Music
      • Pictures
      • Saved Games
      • Searches
      • Videos
    • Computer
      • WebServer (\\10.0.0.80) (W:)
      • Local Disk (C:)
        • inetpub
          • AdminScripts
Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

You can seamlessly populate RadTreeView from XML.

  • Loading from XML file
    RadTreeView1.LoadContentFile("TreeView.xml");
    
  • Loading from XML string
    RadTreeView1.LoadXml("<Tree><Node Text="Books"/><Node Text="Music"/></Tree>");
    

You can also retrieve the current RadTreeView structure in XML format:

  • C#
    string xml = RadTreeView1.GetXml();
    
  • VB
    Dim xml as String = RadTreeView1.GetXml()
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • TreeView.xml
<%@ Page AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="TreeView.Examples.Programming.XmlFile.DefaultCS"Language="c#"  %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-containers">
        <div class="demo-container size-medium">
            <h2>Populated via the LoadContentFile method</h2>
            <telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1" runat="server" Height="350px" Width="300" >
            </telerik:RadTreeView>
        </div>
        <div class="demo-container size-thin">
            <h2>Bound to XmlDataSource</h2>
            <telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView2" runat="server" DataSourceID="XmlDataSource1" Height="350px" Width="300" >
                <DataBindings>
                    <telerik:RadTreeNodeBinding DataMember="Node" TextField="Text" ImageUrlField="ImageUrl"
                        ExpandedField="Expanded"></telerik:RadTreeNodeBinding>
                </DataBindings>
            </telerik:RadTreeView>
        </div>
    </div>
    <asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="TreeView.xml" XPath="/Tree/Node"></asp:XmlDataSource>
    </form>
</body>
</html>

Find Assistance

Help Us Improve

Was this example helpful?