Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
Self Referenceing WHDS with Dataset tied into the Ajax WebDataTree

Well after a few hours I'm getting fustrated. It seemed easy with the older webtree.

Simply I would like to do the following using WHDS, a DataSet, and a WebDataTree in CODE BEHIND.

DataTree should look like the following:



 - Japan

+North America


 -United States

DataSet Table would look like this:

State Name  |  Region

Canada         | North American

China             | Asia

Japan            | Asia


Quick Pseduo Code:

whds.datasource = getDataSet();

// Not really sure how to get self referencing columns with whds.

WebDataTree.DataSource = whds;



Any help would be greatly appreciated.




  • 3147
    Suggested Answer


    Here is a short exampla how to achieve that:

      <ig:WebDataTree ID="WebDataTree1" runat="server" Height="500px" Width="400px"
      InitialExpandDepth="0" InitialDataBindDepth="-1">
       <ig:DataTreeNodeBinding DataMember="Region" TextField="Name" ValueField="RegionID" />
       <ig:DataTreeNodeBinding DataMember="Country" TextField="Name" ValueField="CountryID" />


    And code-behind:

     protected void Page_Load(object sender, EventArgs e)
      if (!IsPostBack)
       DataSet data = GetData();
       WebDataTree1.DataSource = data;

     private DataSet GetData()
      DataSet data = new DataSet();

      DataTable tableRegion = new DataTable("Region");
      tableRegion.Columns.Add("RegionId", typeof(int));
      tableRegion.Columns.Add("Name", typeof(string));
      tableRegion.PrimaryKey = new DataColumn[] { tableRegion.Columns["RegionId"] };

      tableRegion.Rows.Add(1, "North America");
      tableRegion.Rows.Add(2, "Asia");

      DataTable tableCountry = new DataTable("Country");
      tableCountry.Columns.Add("CountryId", typeof(int));
      tableCountry.Columns.Add("RegionId", typeof(int));
      tableCountry.Columns.Add("Name", typeof(string));
      tableCountry.PrimaryKey = new DataColumn[] { tableRegion.Columns["CountryId"] };

      tableCountry.Rows.Add(1, 1, "Canada");
      tableCountry.Rows.Add(2, 2, "China");
      tableCountry.Rows.Add(3, 2, "Japan");


      DataColumn parentColumn = tableRegion.Columns["RegionId"];
      DataColumn childColumn = tableCountry.Columns["RegionId"];

      data.Relations.Add(parentColumn, childColumn);

      return data;