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

    我还是会相信,星星会说话,石头会开花,穿过夏天的栅栏和冬天的风雪过后,你终会抵达。
  • 相关阅读:
    软件需求分析阅读笔记2
    Ubuntu上的Hbase集群搭建
    Form的Load事件的添加
    软件需求与分析大作业进度(二)
    软件需求与分析大作业进度(一)
    第四周学习进度总结
    使用vmware+Ubuntu搭建hadoop集群
    团队十日冲刺10
    用户模板和用户场景
    团队十日冲刺9
  • 原文地址:https://www.cnblogs.com/dfxyw/p/5080055.html
Copyright © 2011-2022 走看看