Adding Data in Treeview from database
-
Hi i am trying to add data in tree view control from database, I have folders and documents & sub folders in those folders. so i want to show hierarchy of folders in treeview. my code is as under Here I have table called folder and in this table unique key is ID and parent key is ParentFolderID which reference to Id of the same table so if there are sub folders then ParentFolderId will be parent Folder's ID. So if there is table which is root level then its ParentFolderID will be reference to itself. Try RootFolderStr = "Select Name from Folder where ID=ParentFolderID" dr = temp.ExecuteDataReader(RootFolderStr) While dr.Read Root = dr("Name") tNode.Text = Root Tree1.Nodes.Add(tNode) End While Catch ex As Exception MsgBox(ex.Message) Finally dr.Close() End Try when i am adding one item it works fine but if there are more items then it returns error "Index must be within the bounds of the List.Parameter name: index" So please help if any one knows the answer. Thanks in advance
-
Hi i am trying to add data in tree view control from database, I have folders and documents & sub folders in those folders. so i want to show hierarchy of folders in treeview. my code is as under Here I have table called folder and in this table unique key is ID and parent key is ParentFolderID which reference to Id of the same table so if there are sub folders then ParentFolderId will be parent Folder's ID. So if there is table which is root level then its ParentFolderID will be reference to itself. Try RootFolderStr = "Select Name from Folder where ID=ParentFolderID" dr = temp.ExecuteDataReader(RootFolderStr) While dr.Read Root = dr("Name") tNode.Text = Root Tree1.Nodes.Add(tNode) End While Catch ex As Exception MsgBox(ex.Message) Finally dr.Close() End Try when i am adding one item it works fine but if there are more items then it returns error "Index must be within the bounds of the List.Parameter name: index" So please help if any one knows the answer. Thanks in advance
Include Microsoft.Web.UI.WebControls.dll in your project. For runtime addition of nodes for TreeView control do following steps //On aspx page register TreeView as <%@ Page language="c#" Codebehind="TreeControl.aspx.cs" AutoEventWireup="false" Inherits="UserControlApplication.TreeControl" %> //Treeview Control //Add the root node for User Control Tree1 in .cs file TreeNode tNode = new TreeNode(); tNode.Text="Root"; tree1.Nodes.Add(tNode); //Add Child Node to root node tNode TreeNode tChileNode1 = new TreeNode(); tChileNode1.Text = str;//This string is the information retrieved form database tNode.Nodes.Add(tChileNode1);
#Abhi#
-
Include Microsoft.Web.UI.WebControls.dll in your project. For runtime addition of nodes for TreeView control do following steps //On aspx page register TreeView as <%@ Page language="c#" Codebehind="TreeControl.aspx.cs" AutoEventWireup="false" Inherits="UserControlApplication.TreeControl" %> //Treeview Control //Add the root node for User Control Tree1 in .cs file TreeNode tNode = new TreeNode(); tNode.Text="Root"; tree1.Nodes.Add(tNode); //Add Child Node to root node tNode TreeNode tChileNode1 = new TreeNode(); tChileNode1.Text = str;//This string is the information retrieved form database tNode.Nodes.Add(tChileNode1);
#Abhi#
-
hi abhi i have try this but it will work when i have only one row. if there are more rows that i m fetching then error is coming that i have asked in my previous question so if there is another way to solve it please let me know Thanks
Hi Try this - Define your chile node inside while loop and fill it and after it add to root node. :->:->:->
#Abhi#