家乡的夜景,小小的月牙儿挂在湛蓝湛蓝的天空上,把淡淡的光洒在军舰上,军舰就像披上了一件银白色的棉袄,海面上波光粼粼,海浪轻轻地拍打着礁石,像一位母亲在抚摸着孩子的小脚丫。
在ASP.NET中,TreeView的使用很普遍,把它利用上来
首先加入TreeView控件
<asp:TreeView ID="driverInfoView" runat="server" ImageSet="XPFileExplorer" OnTreeNodePopulate="driverInfoView_TreeNodePopulate"> </asp:TreeView>
当页面加载的时候,写下以下代码
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); } }
设置TreeView节点的事件
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); } }
本文ASP.NET中使用TreeView显示文件的方法到此结束。人生不要被过去所控制,决定你前行的,是未来。小编再次感谢大家对我们的支持!