private void DisplayUserTree(int nodeId, int role)
{
this.TreeView1.Nodes.Clear();
List<SysFun> fatherSysFun = SysFunManager.GetSysFunByParentNodeId(nodeId, role);//从数据库中活的父节点
foreach (SysFun SysFunOne in fatherSysFun)
{
string strText = SysFunOne.DisplayName.ToString();
string strId = SysFunOne.NodeId.ToString();
string strUrl = SysFunOne.NodeURL.ToString();
string strImg = "~/images/menuopen.gif";
TreeNode fatherTreeNode = CreateTreeNode(strText, strId, strUrl, strImg);//根据节点信息,创建父节点
List<SysFun> childSysFun = SysFunManager.GetSysFunByParentNodeId(Convert.ToInt32(strId), role);//从数据库中活的子节点
foreach (SysFun SysFunTwo in childSysFun)
{
string _strText = SysFunTwo.DisplayName.ToString();
string _strId = SysFunTwo.NodeId.ToString();
string _strUrl = SysFunTwo.NodeURL.ToString();
string _strImg = "~/images/OpenTree.gif";
TreeNode childTreeNode = CreateTreeNode(_strText, _strId, _strUrl, _strImg);//根据节点信息,创建子节点
fatherTreeNode.ChildNodes.Add(childTreeNode);//将子节点加入到父节点下
}
this.TreeView1.Nodes.Add(fatherTreeNode);//将父节点加入到用户权限TreeView中
}
this.TreeView1.ExpandDepth = 0;
}
/// <summary>
/// 创建树的节点
/// </summary>
/// <param name="strText"></param>
/// <param name="strId"></param>
/// <param name="strUrl"></param>
/// <param name="strImg"></param>
/// <returns></returns>
private TreeNode CreateTreeNode(string strText, string strId, string strUrl, string strImg)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = strText;
treeNode.Value = strId;
treeNode.NavigateUrl = strUrl;
treeNode.ImageUrl = strImg;
return treeNode;
}
- 本文标题: ASP.NET SQL 动态加载树
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
- 上一篇:SQL 修改数据库名称
- 下一篇: 在ASP.NET中,实现多个RadioButt