2012-03-18
<?xml version="1.0" encoding="utf-8" ?> <Root url="Index.aspx" name="日报系统总览" describe="日报系统"> <Parent url="Default.aspx" name="任务管理" describe="任务管理" > <Child url="MyWork.aspx" name="我的工作台" describe="我的工作台" /> <Child url="OverWork.aspx" name="以完成的任务" describe="以完成的任务" /> <Child url="dailyPaper.aspx" name="日报" describe="日报" /> <Child url="weekly.aspx" name="周报" describe="周报" /> </Parent> </Root> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Left : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { XmlDataSource XmlComputer = new XmlDataSource(); //建立XmlDataSource实例 XmlComputer.ID = "ComputerProducts"; XmlComputer.DataFile = "XMLFile.xml"; //指定XmlDataSource来源为XML文件 TreeView1.DataSource = XmlComputer; //指定xml数据 //或是您可以用下列方式声明 //指定TreeView的数据源为XmlComputer //TreeView1.DataSourceID = XmlComputer.UniqueID; //Page.Controls.Add(XmlComputer); //建立根节点 TreeNodeBinding RootBinding = new TreeNodeBinding(); RootBinding.DataMember = "Root"; //指定RootBinding数据成员为Root节点 RootBinding.NavigateUrlField = "url"; //指定RootBinding的NavigateUrl为url RootBinding.TextField = "name"; //指定TextField为name RootBinding.ToolTipField = "describe"; //指定ToolTipField为describe RootBinding.Target = "mainframe"; //将RootBinding加入DataBindings之中 TreeView1.DataBindings.Add(RootBinding); //建立父节点 TreeNodeBinding ParentBinding = new TreeNodeBinding(); ParentBinding.DataMember = "Parent"; ParentBinding.NavigateUrlField = "url"; ParentBinding.TextField = "name"; ParentBinding.ToolTipField = "describe"; ParentBinding.Target = "mainframe"; TreeView1.DataBindings.Add(ParentBinding); //建立子节点(叶节点) TreeNodeBinding ChildBinding = new TreeNodeBinding(); ChildBinding.DataMember = "Child"; ChildBinding.NavigateUrlField = "url"; ChildBinding.TextField = "name"; ChildBinding.ToolTipField = "describe"; ChildBinding.Target = "mainframe"; TreeView1.DataBindings.Add(ChildBinding); //Page.FindControl("Form1").Controls.Add(TreeView1); this.TreeView1.DataBind(); //TreeView进行数据绑定 } } }
编辑器加载中...