码迷,mamicode.com
首页 > Web开发 > 详细

如何用ASPxTreeView建立三级树(显示及数据绑定)

时间:2015-12-27 16:10:06      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

示例如图:技术分享

 

//设置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

 

如何用ASPxTreeView建立三级树(显示及数据绑定)

标签:

原文地址:http://www.cnblogs.com/dfxyw/p/5080055.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!