The example in this article tells you how ASP.net uses the TreeView to display files, and is a very useful technique. Share to everyone for your reference. The implementation methods are as follows:
The TreeView is commonly used in asp.net, and here's a detailed account of how you use the TreeView to display files.
1. Add the TreeView control First:
<asp:treeview id= "Driverinfoview" runat= "imageset=" Xpfileexplorer "ontreenodepopulate=" DriverInfoView_ Treenodepopulate ">
</asp:TreeView>
2. When the page is loaded, write down the following code:
protected void Page_Load (object sender, EventArgs e)
{
foreach (DriveInfo driverinfo in Driveinfo.getdrives ()) c3/>{
TreeNode newNode = new TreeNode ();
newnode.expanded = false;
Newnode.populateondemand = true;
Newnode.value = Driverinfo.name;
if (Driverinfo.isready)
{
Newnode.text = driverinfo.name + "(" + Driverinfo.volumelabel + ")";
}
else
{
Newnode.text = driverinfo.name + "(Not ready yet)";
}
THIS.DRIVERINFOVIEW.NODES.ADD (NewNode);
}
3. Set events for the TreeView node:
protected void Driverinfoview_treenodepopulate (object sender, TreeNodeEventArgs e)
{
DirectoryInfo dictinfo = New DirectoryInfo (e.node.value);
foreach (DirectoryInfo directory in Dictinfo.getdirectories ())
{
TreeNode newNode = new TreeNode ();
newnode.expanded = false;
Newnode.populateondemand = true;
Newnode.text = Directory. Name;
Newnode.value = Directory. FullName;
E.node.childnodes.add (NewNode);
}
foreach (FileInfo FileInfo in Dictinfo.getfiles ())
{
TreeNode newNode = new TreeNode ();
Newnode.text = Fileinfo.name;
Newnode.value = Fileinfo.fullname;
E.node.childnodes.add (NewNode);
}
It is believed that the example mentioned in this article has certain reference value for the ASP.net program design.