Forgive me for sounding completely amateurish, but I'm using NetAdvantage 2007 V1 and I'm trying to DataBind to the WebTree and am having a bit of difficulty. What we are trying to display is a folder hierarchy that is stored in a SQL Database. All the folder information will be in one table and a folder will be related to its parent via a parent_folder_id. The dataset will look similar to this
folder_id folder_name parent_folder_id
1 Root NULL
2 Child 1
3 Child2 1
4 Child3 3
The level depth will be determined after the Dataset is filled. The only DataRelation I created was from the table to itself via the folder_id and parent_folder_id columns. I was able to create a tree that had the data nested correctly, the only problem was that the nested nodes also showed up as root nodes with nothing underneath.
How can I accomplish this?
Neal
The above example only works for doing relational tables.... and probably like you was not much help. Below is how I used a single hierarchical structured table to build the Tree control.
Step1: Declare a publicly accessable DataTable to be used by the funcitons.---------------------------------------------------------------------------------------------------------------
DataSet NavListDS = new DataSet();
Step2: Add the calls to bind the treview on the first pageview. Note the ID of your UltraWebTree goes here.---------------------------------------------------------------------------------------------------------------
protected void page_load(object sender, EventArgs e) { if (!Page.IsPostBack) { // first load DataSet LoadDataSet(); // Build using 0 as the Root ID(Root=0 in DB) BuildMenu(UltraWebTree1.Nodes, 0); } }
Step3: Add the Functions---------------------------------------------------------------------------------------------------------------
#region UltraWebTree Builder protected void LoadDataSet() { //Custom Query (I actually use the ObjectDataSource and Fill a datatable, but wanted to show ease of use here...) //pull your connection string from Web.Config String conn = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //Select your NodesID, Text(name), and parent node from the table(mine is called NavList) String strSQL = "SELECT NodeId, Name, ParentNode FROM [NavList]"; SqlDataAdapter myAdapter = new SqlDataAdapter(strSQL, conn); //Fill that DataSet we created up top in Step1 myAdapter.Fill(NavListDS, "NavList"); } private void BuildMenu(Infragistics.WebUI.UltraWebNavigator.Nodes nodes, Int32 IntParent) { Int32 ThisID; String ThisName; // Pull the NavList Table from the Dataset and filter it down to get just the nodes we are looking for. // NOTE ParentNode is the name of your parent node column in your database DataRow[ children = NavListDS.Tables["NavList"].Select("ParentNode='" + IntParent + "'"); //no child nodes, exit function if (children.Length == 0) return; foreach (DataRow child in children) { // step 1, get the Node's ID ThisID = Convert.ToInt32(child.ItemArray[0]); // step 2 get the Nodes Text ThisName = Convert.ToString(child.ItemArray[1]); // step 3 Infragistics.WebUI.UltraWebNavigator.Node NewNode = new Infragistics.WebUI.UltraWebNavigator.Node(); NewNode.Text = ThisName; NewNode.DataKey = ThisID; // step 4 nodes.Add(NewNode); // step 5 BuildMenu(NewNode.Nodes, ThisID); } } #endregion
---------------------------------------------------------------------------------------------------------------
Good Luck !