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 !
See Infragistics Example Below:You can also get to this by going to http://samples.infragistics.com:)
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load WebPanel2.Visible = WebSamplesVB.Config.ShowDescription ' Put user code to initialize the page here If Not Me.IsPostBack Then ' Get Database connection path for nwind.mdb oleDbConnection1.ConnectionString = WebSamplesVB.Config.NorthwindMDBConnString customersAdapter.Fill(dataSet11, "Customers") ordersAdapter.Fill(dataSet11, "Orders") orderDetailsAdapter.Fill(dataSet11, "Order Details") Try dataSet11.Relations.Add("CustOrders", dataSet11.Tables("Customers").Columns("CustomerID"), dataSet11.Tables("Orders").Columns("CustomerID")) Catch x As System.Exception Dim s As String = x.Message Label1.Text = x.Message End Try Try dataSet11.Relations.Add("OrderDetails", dataSet11.Tables("Orders").Columns("OrderID"), dataSet11.Tables("Order Details").Columns("OrderID")) Catch x As System.Exception Label1.Text = x.Message End Try Me.UltraWebTree1.DataSource = dataSet11 Me.UltraWebTree1.Levels(0).LevelKeyField = "CompanyName,CustomerID" Me.UltraWebTree1.Levels(2).LevelKeyField = "OrderID,ProductID" Me.UltraWebTree1.Levels(0).RelationName = "CustOrders" Me.UltraWebTree1.Levels(0).ColumnName = "CompanyName" Me.UltraWebTree1.Levels(1).RelationName = "OrderDetails" Me.UltraWebTree1.Levels(1).ColumnName = "OrderId" Me.UltraWebTree1.Levels(2).ColumnName = "ProductId" Me.UltraWebTree1.DataMember = "Customers" Me.UltraWebTree1.DataBind() End If End Sub 'Page_Load