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 Control In ASP.net

TreeView Control In ASP.net

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-net
12 Posts 7 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 Manas Bhardwaj

    Sachin Dubey wrote:

    And i have to use object datasource..

    So, what is the problem?

    Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

    S Offline
    S Offline
    Sachin Dubey
    wrote on last edited by
    #3

    what shuld be the process flo in this... i never used treeview with datasource i only used with javascript..

    1 Reply Last reply
    0
    • S Sachin Dubey

      Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #4

      Sachin Dubey wrote:

      Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..

      What is your question ? Do you want to bind the data from database into table or what ?

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Visit My Latest Article : Beginner's Guide : Exploring IIS 6.0 With ASP.NET

      S 1 Reply Last reply
      0
      • A Abhijit Jana

        Sachin Dubey wrote:

        Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..

        What is your question ? Do you want to bind the data from database into table or what ?

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Visit My Latest Article : Beginner's Guide : Exploring IIS 6.0 With ASP.NET

        S Offline
        S Offline
        Sachin Dubey
        wrote on last edited by
        #5

        yes i want to bind data from db only but only using objectdatasource.. how can i handel the node click to show subcategories..

        N 1 Reply Last reply
        0
        • S Sachin Dubey

          yes i want to bind data from db only but only using objectdatasource.. how can i handel the node click to show subcategories..

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #6

          You can't use ObjectDataSource here. A tree view supports only data source that implements IHierarchicalDataSource.

          Navaneeth How to use google | Ask smart questions

          S 1 Reply Last reply
          0
          • N N a v a n e e t h

            You can't use ObjectDataSource here. A tree view supports only data source that implements IHierarchicalDataSource.

            Navaneeth How to use google | Ask smart questions

            S Offline
            S Offline
            Sachin Dubey
            wrote on last edited by
            #7

            Is It Any Control like object datasource or anything else...

            S M N 3 Replies Last reply
            0
            • S Sachin Dubey

              Is It Any Control like object datasource or anything else...

              S Offline
              S Offline
              sashidhar
              wrote on last edited by
              #8

              Try This Link It MAy Help..! [^]

              MyFirstArticlePublished: MenuControlSelectedItem Why Do Some People Forget To Mark as Answer .If It Helps.

              1 Reply Last reply
              0
              • S Sachin Dubey

                Is It Any Control like object datasource or anything else...

                M Offline
                M Offline
                meeram395
                wrote on last edited by
                #9

                Get the result set in a Collection Object and loop through it. 1) First, get the dataset in Businesslayerclass as below:(eg:businessclass name is Employee)

                public static Collection <Employee>GetData()
                {
                Collection<EmployeeData>empcollection = new Collection<EmployeeData>();
                foreach (DataRow datarow in dataset1.Table[0].Rows)
                {
                //Declare the properties and assign the value;
                }

                }

                1. In UI, call this method as below:

                Employee emp = new Employee();
                Collection<Employee>empcollection = new Collection<Employee>();
                foreach (Employee emp1 in empcollection)
                {
                TreeNode tn = new TreeNode(emp1.Name)//if you declare the property as Name.
                tn.OnPopulateDemand = true;
                TreeView1.Nodes.Add(tn);
                }

                Hope this helps. :)

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

                N 1 Reply Last reply
                0
                • M meeram395

                  Get the result set in a Collection Object and loop through it. 1) First, get the dataset in Businesslayerclass as below:(eg:businessclass name is Employee)

                  public static Collection <Employee>GetData()
                  {
                  Collection<EmployeeData>empcollection = new Collection<EmployeeData>();
                  foreach (DataRow datarow in dataset1.Table[0].Rows)
                  {
                  //Declare the properties and assign the value;
                  }

                  }

                  1. In UI, call this method as below:

                  Employee emp = new Employee();
                  Collection<Employee>empcollection = new Collection<Employee>();
                  foreach (Employee emp1 in empcollection)
                  {
                  TreeNode tn = new TreeNode(emp1.Name)//if you declare the property as Name.
                  tn.OnPopulateDemand = true;
                  TreeView1.Nodes.Add(tn);
                  }

                  Hope this helps. :)

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

                  N Offline
                  N Offline
                  N a v a n e e t h
                  wrote on last edited by
                  #10

                  That comes closer but your code will only add nodes at the root level. This will not give hierarchical structure. To get a hierarchical structure, you should have some mechanism to identify the nodes parent and child nodes. I have answered a similar question a while back. See here[^] if you are interested.

                  Navaneeth How to use google | Ask smart questions

                  1 Reply Last reply
                  0
                  • S Sachin Dubey

                    Is It Any Control like object datasource or anything else...

                    N Offline
                    N Offline
                    N a v a n e e t h
                    wrote on last edited by
                    #11

                    Are you aware about the existence of documentation?[^]. Here is what it says: _The TreeView control can also be bound to data. You can use either of two methods to bind the TreeView control to the appropriate data source type:

                    • The TreeView control can use any data source control that implements the IHierarchicalDataSource interface, such as an XmlDataSource control or a SiteMapDataSource control. To bind to a data source control, set the DataSourceID property of the TreeView control to the ID value of the data source control. The TreeView control automatically binds to the specified data source control. This is the preferred method to bind to data.
                    • The TreeView control can also be bound to an XmlDocument object or a DataSet object with relations. To bind to one of these data sources, set the DataSource property of the TreeView control to the data source, and then call the DataBind method.

                    _

                    Navaneeth How to use google | Ask smart questions

                    1 Reply Last reply
                    0
                    • S Sachin Dubey

                      Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..

                      P Offline
                      P Offline
                      prashantagro
                      wrote on last edited by
                      #12

                      Better If you use xml. Create a xml file xtracting data from both the table(Suppose filename is x.xml) <menu type="root" value="HOME" url="~/Accounts/Index1.aspx"> <submenu type="folder" value="Fruits"> <state type="document" url="~/HR/a.aspx" value="Apple"/> <state type="document" url="~/HR/b.aspx" value="Mango"/> <state type="document" url="~/hr/c.aspx" value="Grapes"/> </submenu> </menu> Add a treeview Control on your form page in page_load section paste following codes: In CodeBehindfile XmlDataSource obxlmAdditional = new XmlDataSource(); obxlmAdditional.DataFile = "/x.xml"; treeMenu.DataSource = obxlmAdditional; treeMenu.DataBind();

                      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