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:
+Asia
-China
- Japan
+North America
-Canada
-United States
DataSet Table would look like this:
State Name | Region
Canada | North American
China | Asia
Japan | Asia
etc...
Quick Pseduo Code:
whds.datasource = getDataSet();
// Not really sure how to get self referencing columns with whds.
WebDataTree.DataSource = whds;
WebDataTree.BindData();
Any help would be greatly appreciated.
-DooMer
Hi,
Here is a short exampla how to achieve that:
<ig:WebDataTree ID="WebDataTree1" runat="server" Height="500px" Width="400px" InitialExpandDepth="0" InitialDataBindDepth="-1"> <DataBindings> <ig:DataTreeNodeBinding DataMember="Region" TextField="Name" ValueField="RegionID" /> <ig:DataTreeNodeBinding DataMember="Country" TextField="Name" ValueField="CountryID" /> </DataBindings> </ig:WebDataTree>
And code-behind:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSet data = GetData(); WebDataTree1.DataSource = data; WebDataTree1.DataBind(); } }
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");
data.Tables.Add(tableRegion); data.Tables.Add(tableCountry);
DataColumn parentColumn = tableRegion.Columns["RegionId"]; DataColumn childColumn = tableCountry.Columns["RegionId"];
data.Relations.Add(parentColumn, childColumn);
return data; }