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.
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 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)
{
TreeView1.Nodes.Add(directoryNode);
}
else
{
treeNode.ChildNodes.Add(directoryNode);
}
foreach (FileInfo file in directory.GetFiles())
{
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();
}
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