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. How to get the treeview node count using javascript?

How to get the treeview node count using javascript?

Scheduled Pinned Locked Moved ASP.NET
helpjavascripttutorialquestion
3 Posts 3 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.
  • M Offline
    M Offline
    meeram395
    wrote on last edited by
    #1

    I have a treeview in my form. I need to get the nodes count of the treeview using javascript. I know it is possible in code behind. But I want to do it in javascript. I used the following code,but getting an error that "controlid.Nodes.length" is null or not an object.

    var controlid = document.getElementById('ctl00_MainContent_CreateWizard_UnitsTreeView');
    var nodecount = controlid.Nodes.length;
    alert(nodecount);

    Any idea how to get the count of nodes? Please help. Thanks,

    Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

    A N 2 Replies Last reply
    0
    • M meeram395

      I have a treeview in my form. I need to get the nodes count of the treeview using javascript. I know it is possible in code behind. But I want to do it in javascript. I used the following code,but getting an error that "controlid.Nodes.length" is null or not an object.

      var controlid = document.getElementById('ctl00_MainContent_CreateWizard_UnitsTreeView');
      var nodecount = controlid.Nodes.length;
      alert(nodecount);

      Any idea how to get the count of nodes? Please help. Thanks,

      Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Why do you require this using javascript. treeview renders nested tables. So you need to use javascript to count tables. :) why dont you count in the server side and store in an hidden field ? :doh:

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Microsoft Bing MAP using Javascript
      CLR objects in SQL Server 2005
      Uncommon C# Keywords
      /xml>

      1 Reply Last reply
      0
      • M meeram395

        I have a treeview in my form. I need to get the nodes count of the treeview using javascript. I know it is possible in code behind. But I want to do it in javascript. I used the following code,but getting an error that "controlid.Nodes.length" is null or not an object.

        var controlid = document.getElementById('ctl00_MainContent_CreateWizard_UnitsTreeView');
        var nodecount = controlid.Nodes.length;
        alert(nodecount);

        Any idea how to get the count of nodes? Please help. Thanks,

        Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.

        N Offline
        N Offline
        Nigel Ferrissey
        wrote on last edited by
        #3

        The treeview is rendered as a table, so there is no easy way to get a count of nodes - the nodes are actually table rows and cells. You could apply a css class or other attribute to the nodes in the code behind when you are creating your treeview - then use javascript to count the number of elements with that class - very simple if you use JQuery. Are you adding or removing nodes dynamically with javascript? If not then you could just count them as they are added server-side and embed them in your javascript when the page is rendered. This[^] post will show you how to embed asp.net variable. Hope that helps.

        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