public void CreateNode(TreeNode tn, List<RolePermissionEntity> list)
{
foreach (RolePermissionEntity rp in list)
{
TreeNode tnd = new TreeNode(rp.PermissionName,rp.PermissionCode);
tnd.Checked = rp.HasPermission == 1;
tn.ChildNodes.Add(tnd);
var listChild = (from tab in listAll where tab.ParentPermissionCode == rp.PermissionCode select tab).ToList<RolePermissionEntity>();
if (listChild != null)
{
CreateNode(tnd,listChild);
}
}
}
List<RolePermissionEntity> listAll = new List<RolePermissionEntity>();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InitTreeData();
}
}
public void InitTreeData()
{
this.TreeView1.Nodes.Add(new TreeNode() { Text="根",Value="001"});
listAll.Add(new RolePermissionEntity() { PermissionCode = "10000", PermissionName = "员工管理", ParentPermissionCode = "0", HasPermission = 1 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "11000", PermissionName = "员工管理001", ParentPermissionCode = "10000", HasPermission = 0 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "11100", PermissionName = "员工管理0001", ParentPermissionCode = "11000", HasPermission = 0 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "10001", PermissionName = "企业管理", ParentPermissionCode = "0", HasPermission = 1 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "10002", PermissionName = "薪资管理", ParentPermissionCode = "0", HasPermission = 1 });
var parentList = (from tab in listAll where tab.ParentPermissionCode=="0" select tab).ToList<RolePermissionEntity>();
CreateNode(TreeView1.Nodes[0], parentList);
}
public void CreateNode(TreeNode tn, List<RolePermissionEntity> list)
{
foreach (RolePermissionEntity rp in list)
{
TreeNode tnd = new TreeNode(rp.PermissionName,rp.PermissionCode);
tnd.Checked = rp.HasPermission == 1;
tn.ChildNodes.Add(tnd);
var listChild = (from tab in listAll where tab.ParentPermissionCode == rp.PermissionCode select tab).ToList<RolePermissionEntity>();
if (listChild != null)
{
CreateNode(tnd,listChild);
}
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InitTreeData();
}
}
public void InitTreeData()
{
this.TreeView1.Nodes.Add(new TreeNode() { Text="根",Value="001"});
listAll.Add(new RolePermissionEntity() { PermissionCode = "10000", PermissionName = "员工管理", ParentPermissionCode = "0", HasPermission = 1 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "11000", PermissionName = "员工管理001", ParentPermissionCode = "10000", HasPermission = 0 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "11100", PermissionName = "员工管理0001", ParentPermissionCode = "11000", HasPermission = 0 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "10001", PermissionName = "企业管理", ParentPermissionCode = "0", HasPermission = 1 });
listAll.Add(new RolePermissionEntity() { PermissionCode = "10002", PermissionName = "薪资管理", ParentPermissionCode = "0", HasPermission = 1 });
var parentList = (from tab in listAll where tab.ParentPermissionCode=="0" select tab).ToList<RolePermissionEntity>();
CreateNode(TreeView1.Nodes[0], parentList);
}
public void CreateNode(TreeNode tn, List<RolePermissionEntity> list)
{
foreach (RolePermissionEntity rp in list)
{
TreeNode tnd = new TreeNode(rp.PermissionName,rp.PermissionCode);
tnd.Checked = rp.HasPermission == 1;
tn.ChildNodes.Add(tnd);
var listChild = (from tab in listAll where tab.ParentPermissionCode == rp.PermissionCode select tab).ToList<RolePermissionEntity>();
if (listChild != null)
{
CreateNode(tnd,listChild);
}
}
}
}
}