动态的多级菜单
- 提问者网友:欲望失宠
- 2021-08-10 13:24
- 五星知识达人网友:第四晚心情
- 2021-08-10 13:44
循环绑定
protected void TreeViewShow(int ParentID, TreeNode pNode)
{
DataTable dt = bll_directory.GetList("ParentID=" + ParentID + " order by directorysort").Tables[0];
DataView dv = new DataView(dt);
dv.RowFilter = "ParentID=" + ParentID;
foreach (DataRowView drv in dv)
{
TreeNode tn = new TreeNode();
if (pNode == null)//父节点
{
tn.Text = drv["directoryname"].ToString() + " " + drv["directorynotes"].ToString();
tn.Value = drv["directoryID"].ToString();
if (bll_user.ReadPerMissions(model.PermissionsID,tn.Value))
{
tn.Checked = true;
}
TreeView1.Nodes.Add(tn);
TreeViewShow(Convert.ToInt16(drv["DirectoryID"].ToString()), tn);
}
else//子节点
{
tn.Text = drv["directoryname"].ToString() + " " + drv["directorynotes"].ToString();
tn.Value = drv["directoryID"].ToString();
if (bll_user.ReadPerMissions(model.PermissionsID, tn.Value))
{
tn.Checked = true;
}
pNode.ChildNodes.Add(tn);
TreeViewShow(Convert.ToInt16(drv["DirectoryID"].ToString()), tn);
}
}
}