Hallo, I want to generate my treeview base on the data in my table, for example i have a table TreeStructure that contain
ID -> auto_inc
PARENT_ID -> int
NAME -> character
ID is the primary key, PARENT_ID contains ID of it's parent and NAME is the text I want to display
I want to know is there any way i can generate this data into structured treeview automatically? because before this I do it manually with recursive.
Data Sample ( ID / PARENT_ID / NAME )
1 / 0 / IT , 2 / 0 / SUPPORT , 3 / 0 / SALES
4 / 1 / DEVELOPER , 4 / 1 / NETWORK , 5 / 2 / EDP
tree result :
- IT
---- DEVELOPER
---- NETWORK
- SUPPORT
----EDP
- HRD
thx before :)
Hello,
There are various ways to proceed with binding from a single self-referencing table with ID -> ParentID relation. Recursion is one of them, but there are also easier ways to do it. For example, you can use the Levels collection of the tree to denote the relation - there is a great article describing just that here:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=10087
Another great way to do that, is to use our new WebHierarchicalDataSource control, which lets you create hierarchical relation with a single self-referencing table. We have a nice example that shows that here:
http://samples.infragistics.com/2008.2/webfeaturebrowser/default.htm
(just select the WebHierarchicalDataSource -> Self-Refrencing example from the navigational menu on the left) - full source code is provided there as well, e.g.
<ignav:UltraWebTree ID="UltraWebTree1" runat="server" DataSourceID="WebHierarchicalDataSource1" DefaultImage="" HoverClass="" Indentation="20" StyleSetName="LucidDream" BackColor="#FCFCFC" BorderColor="#E2F2FC" BorderStyle="Solid" BorderWidth="1px" Width="250px" EnableAppStyling="True" ExpandOnClick="True" SingleBranchExpand="True" InitialExpandDepth="2" > <DataBindings> <ignav:NodeBinding DataMember="AccessDataSource1_DefaultView" TextField="LastName" /> </DataBindings> </ignav:UltraWebTree> <aikido:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server"> <DataRelations> <aikido:DataRelation ChildColumns="ReportsTo" ChildDataViewID="AccessDataSource1_DefaultView" ParentColumns="EmployeeID" ParentDataViewID="AccessDataSource1_DefaultView" /> </DataRelations> <DataViews> <aikido:DataView ID="AccessDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="AccessDataSource1" /> </DataViews> </aikido:WebHierarchicalDataSource> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Nwind.mdb" SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [ReportsTo] FROM [Employees]"></asp:AccessDataSource>
Hope this helps.
Hallo Rumen
Thx for the fast reply, this is exactly what i'm looking for, i've tried http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=10087 and it working just fine, thx for your support :)
========================================
I want to ask another questions, maybe it seems silly, before this i use TreeView component that ASP.NET provide,it store text and value when i construct it
TreeNode tn = new TreeNode(text, value);
value contains the ID, and text contains its NAME, so when i click the node, i can identify it from its value
If using UltraWebGrid i haven't found out in what property at Node should i put the ID value , i'm planning on using tag attributes, but somehow e.Node.DataItem always have null value :( .
protected void Tree_NodeBound(object sender, WebTreeNodeEventArgs e){ DataRowView drv = e.Node.DataItem as DataRowView;
e.Node.Tag = drv["ID"].ToString();
}
======================>>>>>
hehe, i already found out how, it can be done when declaring the column name, but i still don't know why e.Node.DataItem is null
for (int i = 0; i < 50; i++){ this.UltraWebTree1.Levels[i].ColumnName = "Name"; this.UltraWebTree1.Levels[i].RelationName = "r1"; this.UltraWebTree1.Levels[i].LevelKeyField = "ID";}