Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. populating treeview from database table

populating treeview from database table

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasedata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gbabu17
    wrote on last edited by
    #1

    hi , I have a database table with 3 columns table1: eid ename parentid 0 root 0 1 child1 0 2 child2 0 3 gchild1 1 4 gchild2 1 5 gchild3 2 6 gchild4 2 7 ggchild1 3 .... and so on. now i want to populate the ASP.NET tree view with the table entries by querying the eids and parentids. i am using ASP.NET 1.1. so i am using microsoft web controls. TreeView: Root ---child1 ------gchild1 ----------ggchild1 ------gchild2 ---child2 ------gchild3 ------gchild4 and so on..... Can some one point to some logic or to some document.

    G 1 Reply Last reply
    0
    • G gbabu17

      hi , I have a database table with 3 columns table1: eid ename parentid 0 root 0 1 child1 0 2 child2 0 3 gchild1 1 4 gchild2 1 5 gchild3 2 6 gchild4 2 7 ggchild1 3 .... and so on. now i want to populate the ASP.NET tree view with the table entries by querying the eids and parentids. i am using ASP.NET 1.1. so i am using microsoft web controls. TreeView: Root ---child1 ------gchild1 ----------ggchild1 ------gchild2 ---child2 ------gchild3 ------gchild4 and so on..... Can some one point to some logic or to some document.

      G Offline
      G Offline
      gbabu17
      wrote on last edited by
      #2

      i am using ASP.NET and C#

      T 1 Reply Last reply
      0
      • G gbabu17

        i am using ASP.NET and C#

        T Offline
        T Offline
        ThePlagueIsBack
        wrote on last edited by
        #3

        I'll try to make this as simple as possible, it's just to give you some idea... Table "TreeItems": item_id, item_parent, item_caption, item_url Main Code: [Run Query] SELECT * FROM TreeItems WHERE IsNull(item_parent) OR IsEmpty(item_parent) [Loop ResultSet] [Create Parent Node] RecursiveScan(thisnode, item_id); [Add Parent Node to Treeview] [End Loop ResultSet] RecursiveScan (Parent_Node, ParentId) { [Run Query] SELECT * FROM TreeItems WHERE item_parent = @ParentId [Loop ResultSet] [Create Child Node] RecursiveAddNodes(thisnode, item_id); [Add Child Node to Parent] [End Loop ResultSet] } of course you will have to adapt to your custom table settings and to the treeview control you are using, I've never used microsoft web controls before.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups