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 's node Click Event

TreeView 's node Click Event

Scheduled Pinned Locked Moved ASP.NET
data-structurestutorial
12 Posts 4 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.
  • R Rocky

    Hello I've populated a tree view from a selfjoined table and now I want to handle the event such that when the user clicks a node, I should just show the data of that record in a formview. I've done something similar in a desktop application but got no idea how to do it here. OnNodeClick was the event in desktop's case but here I dont know how to handle this situation plz give me a few guidelines Thanks

    Rocky You can't climb up a ladder with your hands in your pockets.

    J Offline
    J Offline
    jagadeeshkumar1984
    wrote on last edited by
    #2

    u check once the selection node changed property of the treeview

    R 1 Reply Last reply
    0
    • J jagadeeshkumar1984

      u check once the selection node changed property of the treeview

      R Offline
      R Offline
      Rocky
      wrote on last edited by
      #3

      u mean I should handle SelectedNodeChanged event right void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { //TreeNode }

      Rocky You can't climb up a ladder with your hands in your pockets.

      J 1 Reply Last reply
      0
      • R Rocky

        u mean I should handle SelectedNodeChanged event right void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { //TreeNode }

        Rocky You can't climb up a ladder with your hands in your pockets.

        J Offline
        J Offline
        jagadeeshkumar1984
        wrote on last edited by
        #4

        yes my fnd

        R 2 Replies Last reply
        0
        • J jagadeeshkumar1984

          yes my fnd

          R Offline
          R Offline
          Rocky
          wrote on last edited by
          #5

          I'm on it and hoping for the best :) Thanks

          Rocky You can't climb up a ladder with your hands in your pockets.

          1 Reply Last reply
          0
          • J jagadeeshkumar1984

            yes my fnd

            R Offline
            R Offline
            Rocky
            wrote on last edited by
            #6

            Unable to cast object of type 'System.Web.UI.WebControls.TreeView' to type 'System.Web.UI.WebControls.TreeNode' Thats the error I'm getting, here's my code protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { TreeNode node = (TreeNode)sender; int id = Convert.ToInt32(node.Value); Categories objCat = new Categories(); objCat.Where.ID.Value = id; if (objCat.Query.Load()) { TextBox tb = FormView1.FindControl("CatNameTextBox") as TextBox; tb.Text = objCat.CatName; tb = FormView1.FindControl("DescriptionTextBox") as TextBox; tb.Text = objCat.Description; CheckBox ck = FormView1.FindControl("IsActiveChkBox") as CheckBox; ck.Checked = objCat.IsActive; } } what I wanna do is to take the TreeNode Object coz its text and value are the CategoryName and ID respectively. But its unable to cast it to treeNode. Now what??!!

            Rocky You can't climb up a ladder with your hands in your pockets.

            S 1 Reply Last reply
            0
            • R Rocky

              Unable to cast object of type 'System.Web.UI.WebControls.TreeView' to type 'System.Web.UI.WebControls.TreeNode' Thats the error I'm getting, here's my code protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { TreeNode node = (TreeNode)sender; int id = Convert.ToInt32(node.Value); Categories objCat = new Categories(); objCat.Where.ID.Value = id; if (objCat.Query.Load()) { TextBox tb = FormView1.FindControl("CatNameTextBox") as TextBox; tb.Text = objCat.CatName; tb = FormView1.FindControl("DescriptionTextBox") as TextBox; tb.Text = objCat.Description; CheckBox ck = FormView1.FindControl("IsActiveChkBox") as CheckBox; ck.Checked = objCat.IsActive; } } what I wanna do is to take the TreeNode Object coz its text and value are the CategoryName and ID respectively. But its unable to cast it to treeNode. Now what??!!

              Rocky You can't climb up a ladder with your hands in your pockets.

              S Offline
              S Offline
              Sherin Iranimose
              wrote on last edited by
              #7

              Rocky# wrote:

              TreeNode node = (TreeNode)sender;

              Sender is a TreeView. So convert it to TreeView and from that find the node using FindNode method.

              **$**herin Iranimose

              R 1 Reply Last reply
              0
              • S Sherin Iranimose

                Rocky# wrote:

                TreeNode node = (TreeNode)sender;

                Sender is a TreeView. So convert it to TreeView and from that find the node using FindNode method.

                **$**herin Iranimose

                R Offline
                R Offline
                Rocky
                wrote on last edited by
                #8

                but how will I know which node was clicked? how will I find the node that was clicked? Its EventArgs is having no info regarding that?

                Rocky You can't climb up a ladder with your hands in your pockets.

                V S 2 Replies Last reply
                0
                • R Rocky

                  but how will I know which node was clicked? how will I find the node that was clicked? Its EventArgs is having no info regarding that?

                  Rocky You can't climb up a ladder with your hands in your pockets.

                  V Offline
                  V Offline
                  Venkatesh Mookkan
                  wrote on last edited by
                  #9

                  The TreeViewControl.SelectedNode gives the selected node. You can use it in the SelectedNodeChanged Event of the TreeView.

                  Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot

                  R 1 Reply Last reply
                  0
                  • V Venkatesh Mookkan

                    The TreeViewControl.SelectedNode gives the selected node. You can use it in the SelectedNodeChanged Event of the TreeView.

                    Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot

                    R Offline
                    R Offline
                    Rocky
                    wrote on last edited by
                    #10

                    oh sorry, I didnt see it :doh:

                    Rocky You can't climb up a ladder with your hands in your pockets.

                    1 Reply Last reply
                    0
                    • R Rocky

                      but how will I know which node was clicked? how will I find the node that was clicked? Its EventArgs is having no info regarding that?

                      Rocky You can't climb up a ladder with your hands in your pockets.

                      S Offline
                      S Offline
                      Sherin Iranimose
                      wrote on last edited by
                      #11

                      hi, What about this MyTreeView.SelectedNode

                      **$**herin Iranimose

                      R 1 Reply Last reply
                      0
                      • S Sherin Iranimose

                        hi, What about this MyTreeView.SelectedNode

                        **$**herin Iranimose

                        R Offline
                        R Offline
                        Rocky
                        wrote on last edited by
                        #12

                        yea I got it just a few moments ago. Thanks v much , gave for 5 for that Cheers..

                        Rocky You can't climb up a ladder with your hands in your pockets.

                        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