zoukankan      html  css  js  c++  java
  • 从数据库读取数据绑定到TreeView(内含设置样式,图片)

    例子,纯代码,仅供参考

            /// <summary>
    /// 邦定根节点
    /// </summary>
    public void BindTreeView(DataTable dt)
    {
    DataTable aldt = GetTreeList("").Tables[0];
    //菜单状态
    tv.Nodes.Clear(); // 清空树
    if (Request.QueryString["Type"] == "User")
    {
    TreeNode rootnode = new TreeNode();
    rootnode.Text = "--所有部门--";
    rootnode.Value = "";
    rootnode.ImageUrl = "../img/0_Person.gif";
    rootnode.NavigateUrl = "../User/AdminUser.aspx";
    rootnode.Target = "mainFrame";
    tv.Nodes.Add(rootnode);
    }
    foreach (DataRow r in dt.Rows)
    {
    string nodeid = r["dept_code"].ToString();
    string text = r["dept_name"].ToString();
    this.tv.Font.Name = "宋体";
    this.tv.Font.Size = FontUnit.Parse("9");
    //权限控制菜单
    TreeNode rootnode = new TreeNode();
    rootnode.Text = text;
    rootnode.Value = nodeid;
    rootnode.ImageUrl = "../img/0_Person.gif";
    if (Request.QueryString["Type"] == "User")
    {
    rootnode.NavigateUrl = "../User/AdminUser.aspx?dept_code=" + nodeid;
    }
    else
    {
    rootnode.NavigateUrl = "DeptRight.aspx?dept_code=" + nodeid;
    }
    rootnode.Target = "mainFrame";
    tv.Nodes.Add(rootnode);
    string sonparentid = nodeid;
    CreateNode(sonparentid, rootnode, aldt);
    }

    }
    /// <summary>
    /// 邦定任意节点
    /// </summary>
    public void CreateNode(string parentid, TreeNode parentnode, DataTable dt)
    {
    DataRow[] drs = dt.Select("pare_code= '" + parentid + "'");//选出所有子节点
    foreach (DataRow r in drs)
    {
    string nodeid = r["dept_code"].ToString();
    string text = r["dept_name"].ToString();


    //treeview set
    this.tv.Font.Name = "宋体";
    this.tv.Font.Size = FontUnit.Parse("9");

    TreeNode node = new TreeNode();
    node.Text = text;
    node.Value = nodeid;
    node.ImageUrl = "../img/0_Person.gif";
    if (Request.QueryString["Type"] == "User")
    {
    node.NavigateUrl = "../User/AdminUser.aspx?dept_code=" + nodeid;
    }
    else
    {
    node.NavigateUrl = "DeptRight.aspx?dept_code=" + nodeid;
    }
    node.Target = "mainFrame";
    //node.Expanded=true;
    //node.SelectAction = TreeNodeSelectAction.Expand; //和ASP.NET1.1中TREEVIEW的SelectExpands属性等效
    string sonparentid = nodeid;// or =location

    if (parentnode == null)
    {
    tv.Nodes.Clear();
    parentnode = new TreeNode();
    tv.Nodes.Add(parentnode);
    }
    parentnode.ChildNodes.Add(node);
    CreateNode(sonparentid, node, dt);
    }
    }



  • 相关阅读:
    手写一个类django框架
    Django基础知识
    JQuery知识点总结
    javascript知识点整理
    html知识点一
    mysql之sql语句
    通过非IO阻塞模型实现ftp并发的小代码
    python学习第三十三节(IO模型)
    python学习第三十二节(进程间通信、进程池、协程)
    IntelliJ IDEA For Mac 快捷键
  • 原文地址:https://www.cnblogs.com/jiekk/p/2308587.html
Copyright © 2011-2022 走看看