获取树形视图中选定节点的值 [英] get the value of selected node in the treeview
本文介绍了获取树形视图中选定节点的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码.我想从树形视图控件中获取选定的值,这是我的代码
this is my code. I want to get selected value from the tree view control here is my code
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
推荐答案
TreeView有几种方法可以完成此操作,具体取决于最终要实现的目标.
您可以使用一个SelectedNodeChanged事件.这与列表框的行为相同.
其次,存在NavigateUrl属性,将其设置为空字符串以外的其他值将导致在单击时重定向页面.
有关更多信息和较小示例,请参见此处的文档: ^ ]
希望这对您有所帮助:-)
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 :-)
treeview.SelectedNode.Value;
treeview.SelectedNode.Value ;
这篇关于获取树形视图中选定节点的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文