ASP.NET中使用TreeView顯示文件的方法
在ASP.NET中,TreeView的使用很普遍,把它利用上來
首先加入TreeView控件
<asp:TreeView ID="driverInfoView" runat="server" ImageSet="XPFileExplorer" OnTreeNodePopulate="driverInfoView_TreeNodePopulate"> </asp:TreeView>
當(dāng)頁面加載的時(shí)候,寫下以下代碼
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 + "(還沒準(zhǔn)備好)"; } this.driverInfoView.Nodes.Add(newNode); } }
設(shè)置TreeView節(jié)點(diǎn)的事件
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記住登陸用戶名的具體實(shí)現(xiàn)
ASP.NET記住登陸用戶名的具體實(shí)現(xiàn),需要的朋友可以參考一下2013-06-06Asp.net MVC下使用Bundle合并、壓縮js與css文件詳解
在web優(yōu)化中有一種手段,壓縮js,css文件,減少文件大小,合并js,css文件減少請(qǐng)求次數(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)頁的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09ASP.NET?MVC5網(wǎng)站開發(fā)用戶登錄、注銷(五)
這篇文章主要介紹了ASP.NET?MVC5?網(wǎng)站開發(fā)中用戶登錄、注銷的實(shí)現(xiàn)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-09-09ASP.NET中將聲音文件添加到資源中并進(jìn)行播放的方法
這篇文章主要介紹了ASP.NET中將聲音文件添加到資源中并進(jìn)行播放的方法,實(shí)例分析了聲音文件的添加及播放實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07使用HttpWebRequest向網(wǎng)站模擬上傳數(shù)據(jù)
使用HttpWebRequest向網(wǎng)站模擬上傳數(shù)據(jù)...2006-09-09VS2005打開VS2008項(xiàng)目的2種方法(vs2005怎么打開2008)
vs2008支持.net3.5,而vs2005支持.net2.0,所以使用vs2005打開vs2008的項(xiàng)目,要確定你的項(xiàng)目是.net2.0的,下面介紹二種VS2005打開VS2008項(xiàng)目的方法2014-01-01詳解最好的.NET開源免費(fèi)ZIP庫DotNetZip(.NET組件介紹之三)
本篇文章主要介紹了.NET開源免費(fèi)ZIP庫DotNetZip組件的介紹,可以實(shí)現(xiàn)對(duì)文件的壓縮和解壓,有興趣的朋友可以了解一下。2016-12-12.NET下實(shí)現(xiàn)數(shù)字和字符相混合的驗(yàn)證碼實(shí)例
這篇文章介紹了.NET下實(shí)現(xiàn)數(shù)字和字符相混合的驗(yàn)證碼實(shí)例,有需要的朋友可以參考一下2013-11-11