Binding ASP.NET TreeView Control to a Dataset
<p>In <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.aspx" rel="nofollow">MSDN</a> they say about TreeView control ("Binding to Data" paragraph):</p>

<blockquote>
  <p>The TreeView control can also be bound to an XmlDocument object <strong>or a
  DataSet object with relations</strong>. To bind to one of these data sources,
  set the DataSource property of the TreeView control to the data
  source, and then call the DataBind method.</p>
</blockquote>

<p>So in a simple WebForms page with only a TreeView i wrote:</p>

<pre><code>     DataSet ds = new DataSet();
     DataTable dt = new DataTable("Masters");
     ds.Tables.Add(dt);
     dt.Columns.Add("MasterId", typeof(Int32));
     dt.Columns.Add("Name", typeof(String));
     DataTable dt1 = new DataTable("Details");
     ds.Tables.Add(dt1);
     dt1.Columns.Add("DetailId", typeof(Int32));
     dt1.Columns.Add("MasterId", typeof(Int32));
     dt1.Columns.Add("Name", typeof(String));

     DataRow rw;
     DataRow rw1;
     for (int i = 0; i &lt; 5; i++)
     {
        rw=dt.NewRow();
        dt.Rows.Add(rw);
        rw["MasterId"] = i;
        rw["Name"] = "Master Name " + i.ToString();
        for (int j = 0; j &lt; 10; j++)
        {
           rw1 = dt1.NewRow();
           dt1.Rows.Add(rw1);
           rw1["DetailId"] = i * 5 + j;
           rw1["MasterId"] = i;
           rw1["Name"] = "Detail Name " + j.ToString() + " of Master Name "+ i.ToString();
        }
     }
     ds.Relations.Add(new DataRelation("Masters_Details",dt.Columns["MasterId"], dt1.Columns["MasterId"]));
     TreeView1.DataSource = ds;
     TreeView1.DataBind();
</code></pre>

<p>But in line where i set DataSource it throws exception:</p>

<p><strong>HierarchicalDataBoundControl only accepts data sources that implement IHierarchicalDataSource or IHierarchicalEnumerable.</strong></p>

<p>I understood this occurs because DataSet doesn't implement such interface ... so why did they write is possible to bind to a "DataSet with relations"?
Thank you in advance</p>
