zoukankan      html  css  js  c++  java
  • 如何用ASPxTreeView建立三级树(显示及数据绑定)

    示例如图:三级树效果图

    //设置treeviw默认为第一个菜单打开
    if (ASPxTreeView1.SelectedNode == null)
    ASPxTreeView1.SelectedNode = ASPxTreeView1.Nodes[0];

    前端控件代码:前端代码控件图

    <dx:ASPxTreeView ID="ASPxTreeView1" ClientInstanceName="ASPxTreeView1" runat="server" Width="100%" AllowSelectNode="True" AutoPostBack="false" Styles-NodeText-Font-Size="10px">
    <ClientSideEvents Init="TreeNodeClick" NodeClick="TreeNodeClick" />
    </dx:ASPxTreeView>

    后天代码:

    //数据绑定(重点)

    #region 建立树状菜单

    // 创建主菜单
    private void CreateMenu()
    {
    //MainFrameState mainFrameState = new MainFrameState();
    //d_loginUserId = mainFrameState.LoginUserID;
    DataTable dt = new DataTable();
    dt = platbll.GetB1tree().Tables[0];

    if (dt.Rows.Count > 0)
    {
    DataRow[] mainRow = (DataRow[])dt.Select();
    foreach (DataRow row in mainRow)
    {

    _treenode = new TreeViewNode();

    _treenode.Text = row["PEONAME"].ToString();
    _treenode.ToolTip = row["treepeoid"].ToString();// 储存一个id
    ASPxTreeView1.Nodes.Add(_treenode);
    if (row["treepeoid"].ToString()!=null)
    {
    CreateChildMenu(int.Parse(row["treepeoid"].ToString()), _treenode);
    }

    }
    }

    }
    // B1级菜单
    private void CreateChildMenu(int d_parentID, TreeViewNode TVN)
    {
    DataTable dt = new DataTable();
    dt = platbll.GetB2tree(d_parentID).Tables[0];
    DataRow[] childRow = (DataRow[])dt.Select();
    foreach (DataRow row in childRow)
    {
    _treenode = new TreeViewNode();

    _treenode.Text = row["PEONAME"].ToString();
    _treenode.ToolTip = row["treepeoid"].ToString();
    TVN.Nodes.Add(_treenode);
    // ASPxTreeView1.Nodes.Add(TVN);
    if (row["treepeoid"].ToString() != null)
    {
    CreateChildMenu1(int.Parse(row["treepeoid"].ToString()), _treenode);
    }
    }
    }

    // B2、B3级菜单
    private void CreateChildMenu1(int d_parentID, TreeViewNode TVN)
    {
    DataTable dt = new DataTable();
    dt = platbll.GetB2tree(d_parentID).Tables[0];
    DataRow[] childRow = (DataRow[])dt.Select();
    foreach (DataRow row in childRow)
    {
    _treenode = new TreeViewNode();

    _treenode.Text = row["PEONAME"].ToString();
    _treenode.ToolTip = row["treepeoid"].ToString();
    TVN.Nodes.Add(_treenode);

    }
    }
    #endregion

    我还是会相信,星星会说话,石头会开花,穿过夏天的栅栏和冬天的风雪过后,你终会抵达。
  • 相关阅读:
    nginx http和https共存
    jQuery prop方法替代attr方法
    idea内置tomcat中java代码热更新
    Linux磁盘空间查看、磁盘被未知资源耗尽
    Mysql order by与limit混用陷阱
    IIS 架构解析
    asp.net MVC 应用程序的生命周期
    Linq专题之var关键字
    ThoughtWorks 2016年第1期DNA活动总结
    对象的深拷贝--反射
  • 原文地址:https://www.cnblogs.com/dfxyw/p/5080055.html
Copyright © 2011-2022 走看看