Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code. I want to get selected value from the tree view control here is my code
C#
protected void Page_Load(object sender, EventArgs e)
      {

if (Page.IsPostBack == false)
            {
                DirectoryInfo RootDir = new DirectoryInfo(Server.MapPath("~/AudioFiles"));

                // output the directory into a node
                TreeNode RootNode = OutputDirectory(RootDir, null);

                // add the output to the tree
                TreeView1.Nodes.Add(RootNode);
            }

        }
 TreeNode OutputDirectory(DirectoryInfo directory, TreeNode parentNode)
    {
        // validate param
        if (directory == null) 
            return null; 

        // create a node for this directory
        TreeNode DirNode = new TreeNode(directory.Name);

        // get subdirectories of the current directory
        DirectoryInfo[] SubDirectories = directory.GetDirectories();

        // OutputDirectory(SubDirectories[0], "Directories");
        // output each subdirectory
        for (int DirectoryCount = 0; DirectoryCount < SubDirectories.Length; DirectoryCount++)
        {
            OutputDirectory(SubDirectories[DirectoryCount], DirNode);
        }

        // output the current directories file
        FileInfo[] Files = directory.GetFiles();
        for (int FileCount = 0; FileCount < Files.Length; FileCount++)
        {
            DirNode.ChildNodes.Add(new TreeNode(Files[FileCount].Name));
        }
       
        // if the parent node is null, return this node
        // otherwise add this node to the parent and return the parent
        if (parentNode == null)
        {
            return DirNode;
        }
        else
        {
            parentNode.ChildNodes.Add(DirNode);
            return parentNode;
        }
    }


please suggest

Thank you
Posted
v2

The TreeView has several ways you can do this, depending on what you what to achieve in the end.

There is a SelectedNodeChanged event which you could use. This behaves the same as with a listbox.

Secondly there is the NavigateUrl property, setting this to a value other than empty string will cause a page redirect upon click.

See the documentation here for more information and a small sample: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview(v=vs.100).aspx[^]

Hope this helps you on your way :-)
 
Share this answer
 
treeview.SelectedNode.Value ;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900