zoukankan      html  css  js  c++  java
  • 读取xml 树形结构

    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进行数据绑定            
            }
        } 
    }
    

      

    编辑器加载中...

  • 相关阅读:
    dajngo ORM查询中select_related的作用,博客主题的定制,从数据库中按照年月筛选时间
    Django数据查询中对字段进行排序
    Django验证码实现
    django登录注册验证之密码包含特殊字符,确认密码一致实现,Form验证
    django模板传入参数的处理方式与反向生成url
    在django中使用循环与条件语言
    django的模板的继承与导入
    sublime3故障收集emmet无法安装pyv8
    [SQL SERVER系列]之嵌套子查询和相关子查询
    [SQL SERVER系列]读书笔记之SQL注入漏洞和SQL调优
  • 原文地址:https://www.cnblogs.com/zmmlczy/p/2405043.html
Copyright © 2011-2022 走看看