ASP.NET中使用TreeView顯示文件的方法
在ASP.NET中,TreeView的使用很普遍,把它利用上來
首先加入TreeView控件
<asp:TreeView ID="driverInfoView" runat="server" ImageSet="XPFileExplorer" OnTreeNodePopulate="driverInfoView_TreeNodePopulate"> </asp:TreeView>
當(dāng)頁面加載的時候,寫下以下代碼
protected void Page_Load(object sender, EventArgs e) { foreach (DriveInfo driverInfo in DriveInfo.GetDrives()) { 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 + "(還沒準備好)"; } this.driverInfoView.Nodes.Add(newNode); } }
設(shè)置TreeView節(jié)點的事件
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); } }
相關(guān)文章
比較簡單的將數(shù)據(jù)信息導(dǎo)入wrod文檔方案(C# for word)
史上最簡單將數(shù)據(jù)信息導(dǎo)入wrod文檔方案(C# for word)2010-01-01Asp.net MVC下使用Bundle合并、壓縮js與css文件詳解
在web優(yōu)化中有一種手段,壓縮js,css文件,減少文件大小,合并js,css文件減少請求次數(shù)。asp.net mvc中為我們提供一種使用c#代碼壓縮合并js和css這類靜態(tài)文件的方法。這篇文章主要介紹了在Asp.net MVC下使用Bundle合并、壓縮js與css文件的方法,需要的朋友可以參考下。2017-03-03ASP.NET?MVC使用Log4Net記錄異常日志并跳轉(zhuǎn)到靜態(tài)頁
這篇文章介紹了ASP.NET?MVC使用Log4Net記錄異常日志并跳轉(zhuǎn)到靜態(tài)頁的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-09-09ASP.NET?MVC5網(wǎng)站開發(fā)用戶登錄、注銷(五)
這篇文章主要介紹了ASP.NET?MVC5?網(wǎng)站開發(fā)中用戶登錄、注銷的實現(xiàn)功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-09-09使用HttpWebRequest向網(wǎng)站模擬上傳數(shù)據(jù)
使用HttpWebRequest向網(wǎng)站模擬上傳數(shù)據(jù)...2006-09-09VS2005打開VS2008項目的2種方法(vs2005怎么打開2008)
vs2008支持.net3.5,而vs2005支持.net2.0,所以使用vs2005打開vs2008的項目,要確定你的項目是.net2.0的,下面介紹二種VS2005打開VS2008項目的方法2014-01-01詳解最好的.NET開源免費ZIP庫DotNetZip(.NET組件介紹之三)
本篇文章主要介紹了.NET開源免費ZIP庫DotNetZip組件的介紹,可以實現(xiàn)對文件的壓縮和解壓,有興趣的朋友可以了解一下。2016-12-12.NET下實現(xiàn)數(shù)字和字符相混合的驗證碼實例
這篇文章介紹了.NET下實現(xiàn)數(shù)字和字符相混合的驗證碼實例,有需要的朋友可以參考一下2013-11-11