We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind XML data to TreeGrid

Platform: ASP.NET Web Forms |
Control: TreeGrid |
Published Date: November 5, 2015 |
Last Revised Date: May 29, 2019

It is possible to bind XML data to TreeGrid by using ParentIdMapping and IdMapping properties, where the xml tags must be mapped as fields in TreeGrid columns. Please refer the below code snippets for importing XML data into TreeGrid.

Code snippets:

In Default.aspx:

<body>
      <form id="Form1" runat="server" onsubmit="return false">
        <ej:TreeGrid runat="server" ID="TreeGridControlEditing" IdMapping="Id"   
            ParentIdMapping="ParentId">
        <columns>
                <ej:TreeGridColumn HeaderText="Task Id" Field="Id" Width="55" EditType="Numeric"/>
                <ej:TreeGridColumn HeaderText="Task Name" Field="Name" EditType="String"/>
                <ej:TreeGridColumn HeaderText="Start Date" Field="StartDate" EditType="Datepicker"/>
                <ej:TreeGridColumn HeaderText="End Date" Field="EndDate" EditType="Datepicker"/>
                <ej:TreeGridColumn HeaderText="Duration" Field="Duration" EditType="Numeric" />
                <ej:TreeGridColumn HeaderText="Progress" Field="PercentDone" EditType="Numeric"/>
         </columns>
         //...
        </ej:TreeGrid>
      </form>
</body>

In XML file:

<?xml version="1.0" encoding="utf-8" ?>
<TreeGridXML>
       <Task>
  <Id>1</Id>
 
  <Name>Planning Schedule</Name> 
 
  <StartDate>02/04/2014</StartDate> 
 
  <EndDate>02/06/2014</EndDate>
 
              <PercentDone>40</PercentDone>
 
  <Duration>4</Duration>
 </Task>
       <Task>
              <Id>2</Id> 
              <Name>Plan Timeline</Name> 
              <StartDate>02/04/2014</StartDate> 
              <EndDate>02/06/2014</EndDate>
              <PercentDone>60</PercentDone>
              <Duration>4</Duration>
              <ParentId>1</ParentId>
       </Task>
//...
</TreeGridXML>
 

In Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace TreeGrid
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet data = new DataSet();
            data.ReadXml(Server.MapPath("~/App_Data/treeGridData.xml"));
            this.TreeGridControlEditing.DataSource = data;
            this.TreeGridControlEditing.DataBind();
        }
    }
}
 

Please find the demo sample link below for XML databinding in TreeGrid

XML databinding

2X faster development

The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon