Master child records in one table , treeview struct, deletion algorithm
Posted on 2004-08-12
I am looking forward for some good algorithm for one of my requirement.
I got a table which will be displayed in frontend in treeview.
So basically records will be navigated through child with parent id.
When building the tree it starts from first record. Then start building one by one with by category which represent which level current node to be built.
Now query here is i want a effective algorithm to delete those child records when parent record is deleted.
My table will be having
ID, Name, ParentID, CategoryID Details, etc...
1 Testing, null, ....., 1
2 Child1 , 1 , ..... , 2
3 Testing1, null, .......,1
4 Child2 , 3 , ..........,2
Above is sample records. But tree node depth will go down to 8 levels. So I cannot assume or hardcode any values.
I want to have a effective algoritm to delete those child nodes from table when deleting parent.
And that deletion should be genric enough to delete at any level. Like if i want to delete just the child alone then also it should be possible.
Let me know if any further details needed.
Looking for it.