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. treeview

treeview

Scheduled Pinned Locked Moved ASP.NET
help
2 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.
  • P Offline
    P Offline
    pratima1
    wrote on last edited by
    #1

    hi, how i will add rootnode,node and subnode dinamically to a treeview control plz help.

    p.sethi

    N 1 Reply Last reply
    0
    • P pratima1

      hi, how i will add rootnode,node and subnode dinamically to a treeview control plz help.

      p.sethi

      N Offline
      N Offline
      Naveed Kamboh
      wrote on last edited by
      #2

      Hi following code migth help you //Populate treeview at root level public void PopulateRootLevel( TreeView tv) { DataTable dt = new DataTable(); string sql = "SELECT MenuId,MenuName,MenuDescription,LinkName,(Select count(*) from menus where Parentid=mns.MenuId and menus.Status='Yes') as childnodecount,SecurityLevel FROM `menus` mns WHERE mns.Status = 'Yes' and mns.parentid is null"; try { connectToDB(); MySqlCommand cmdRoot = new MySqlCommand(sql, connection); MySqlDataAdapter da = new MySqlDataAdapter(cmdRoot); da.Fill(dt); } catch (Exception) { } finally { connection.Close(); connection.Dispose(); } PopulateNodes(dt, tv.Nodes); } //Populate nodes private void PopulateNodes(DataTable dt, TreeNodeCollection nodes) { foreach (DataRow dr in dt.Rows) { TreeNode tn = new TreeNode(); tn.Text = dr["MenuName"].ToString(); tn.Value = dr["MenuID"].ToString(); tn.ToolTip = dr["MenuDescription"].ToString(); tn.NavigateUrl = dr["LinkName"].ToString(); nodes.Add(tn); //If node has child nodes, then enable on-demand populating tn.PopulateOnDemand = int.Parse(dr["childnodecount"].ToString()) > 0; } }

      Naveed Kamboh Complexity kills, Write easy code for your self. isolutionteam

      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