100分送上,了解ComponentArt控件原理的朋友进来看下
刚看了下ComponentArt的Callback控件,其它有个关于实现类似Windows资源管理器的例子。有个问题没有闹明白,请高人指点一下。
例子中,左边是一个ComponentArt的TreeView,是显示类似资源管理器中左边的目录结构,右边是ComponentArt的Grid控件,当点击了左边树上的结点(选中目录)的时候,选中节点下加载出他的子目录,右边Grid中显示出选中的节点(目录)下面的各种文件。而这个例子是用了两个页面来实现的。
首页代码过多不方便例出,基本是这样的,点击节点后,使用Ajax刷新了右边的Grid,但同时加载出选中节的子目录的功能是使用另外一个页面来实现的,代码如下:
<%@ Page Language="C#" AutoEventWireUp="true" %><%@ import Namespace="System.Threading" %><%@ import Namespace="System.IO" %><%@ import Namespace="ComponentArt.Web.UI" %><% Response.ContentType = "text/xml"; %><script language="C#" runat="server">void Page_Load(Object sender,EventArgs e){ ComponentArt.Web.UI.TreeView TreeView1 = new ComponentArt.Web.UI.TreeView(); string dirPath = Request.QueryString["dir"]; dirPath = dirPath.Replace("~", "\\"); // Don't allow browsing the file system outside of the app root if (dirPath.StartsWith(Request.MapPath("~"))) { string[] subDirectories = Directory.GetDirectories(dirPath); foreach (string directory in subDirectories) { string[] parts = directory.Split('\\'); string name = parts[parts.Length-1]; ComponentArt.Web.UI.TreeViewNode node = new ComponentArt.Web.UI.TreeViewNode (); node.Text = name; node.ContentCallbackUrl = "XmlFromFileSystem.aspx?dir=" + directory.Replace("\\", "~"); node.ID = directory.Replace("\\", "~"); TreeView1.Nodes.Add(node); } Response.Write(TreeView1.GetXml()); }}</script>