我想在ASP .NET页面加载中显示树视图的根节点,然后在每个节点点击后,它将显示该节点的数据。 [英] I want to display root nodes of tree view in ASP .NET page load and then after for each node click it will display data of that node.

查看:62
本文介绍了我想在ASP .NET页面加载中显示树视图的根节点,然后在每个节点点击后,它将显示该节点的数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I want to display root nodes of tree view in asp .net page load and then after for each node click it will display data of that node.



当我点击第一个根时,它将只显示第一个根数据。

现在当我点击第二个根节点它将显示第二个根数据隐藏我先前点击的第一个根数据。 />


另外我选择了什么根节点我希望在gridview中显示所有文件的详细信息

即文件名,创建日期,文件路径大小等。



还想在文本编辑器中显示所选文件数据。



我试过的:



Aspx代码如下


When I click on first root it will display only first root data.
now when I click second root node It will display second root data hide first root data which i earlier click.

Also What ever root node I have selected I want display all files details in gridview
i.e file name, created date ,file path size ect.

Also want to display selected file data in text Editor.

What I have tried:

Aspx Code is as follows

    <div>
       <h3>
    Vehicle Details</h3>
<hr>
<asp:TreeView ID="TreeView1" runat="server" ImageSet="XPFileExplorer" NodeIndent="15" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded">
    <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
    <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px"
        NodeSpacing="0px" VerticalPadding="2px">
    <ParentNodeStyle Font-Bold="False" />
    <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
        VerticalPadding="0px" />


        <hr>
        <asp:GridView ID="GridView1" runat="server">
    </div>





Aspx.cs文件代码如下





Aspx.cs file code is as follows

public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                DirectoryInfo rootInfo = new DirectoryInfo(Server.MapPath("~/Vehicles/"));
                this.PopulateTreeView(rootInfo, null);
            }
        }

        private void PopulateTreeView(DirectoryInfo dirInfo, TreeNode treeNode)
        {
            foreach (DirectoryInfo directory in dirInfo.GetDirectories())
            {
                TreeNode directoryNode = new TreeNode
                {
                    Text = directory.Name,
                    Value = directory.FullName
                };

                if (treeNode == null)
                {
                    //If Root Node, add to TreeView.
                    TreeView1.Nodes.Add(directoryNode);
                }
                else
                {
                    //If Child Node, add to Parent Node.
                    treeNode.ChildNodes.Add(directoryNode);
                }

                //Get all files in the Directory.
                foreach (FileInfo file in directory.GetFiles())
                {
                    //Add each file as Child Node.
                    TreeNode fileNode = new TreeNode
                    {
                        Text = file.Name,
                        Value = file.FullName,
                        Target = "_blank",
                        NavigateUrl = (new Uri(Server.MapPath("~/"))).MakeRelativeUri(new Uri(file.FullName)).ToString()
                    };
                    directoryNode.ChildNodes.Add(fileNode);
                }

                PopulateTreeView(directory, directoryNode);
            }
        }

       

        protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
            GetFilesAndFolders();
            //if (e.Node.Parent == null)
            //    return;
            //string strNodeValue = e.Node.Value;
            //foreach (TreeNode node in e.Node.Parent.ChildNodes)
            //{
            //    if (node.Value != strNodeValue)
            //        node.Collapse();
            //}
        }

        public void GetFilesAndFolders()
        {
            DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("~/Vehicles"));
            FileInfo[] fileInfo = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
            GridView1.DataSource = fileInfo;
            GridView1.DataBind();
        }
    }





它是在页面加载时显示所有根节点及其所有子节点。而不是我想只显示所有根节点。

它还显示网格上所有根的所有子节点的所有文件详细信息,而我只想要选择的根子节点



It Is Displaying all root node and all its child node on page load. Instead of that I want to display only All root nodes.
also it is displaying all files details of all child of all root on grid instead I want only selected root childs only

推荐答案

请查看以下链接中提供的解决方案。我希望这会对你有所帮助。

在选择一个节点的TreeView中折叠所有其他节点 [ ^ ]
Please look into the solution provided in below link. I hope this would help you.
Collapse All Other Nodes in TreeView on Selection of One Node[^]


这篇关于我想在ASP .NET页面加载中显示树视图的根节点,然后在每个节点点击后,它将显示该节点的数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆