TreeView and Permissions (I am a small solution)

xiaoxiao2021-03-06  46

I have seen more TreeView and permissions solutions, I feel too complicated, and it is not practical (maybe I am stupid, just personal opinion). Here I use TreeView with database to implement the management of the permissions (roles) shown below. There is a picture can be referring to: First, there should be 2 tables: Table 1: Accounts_Permissioncategories (permission category table) ID Name DESC 01 case processing 02 Statistics report 03 Trademark Query Table 2: Accounts_Permission (permission table) ID CategoryId Name DESC 01 01 Data Record 02 01 Accounting Information Query Private Void Page_Load (Object Sender, System.EventArgs E) {if (! Page.ispostback) {bindPermissioncategories (); bindpermission ();}

Private void bindpermissioncategories () {// Binding permissions category String info = string.empty;

RG.JGJ.Modules.Accounts.Business.PermissionCategory pc = new RG.JGJ.Modules.Accounts.Business.PermissionCategory (); SortedList sl = pc.GetPermissionCategoriesForTreeView (out info); int count = sl.Count;

Microsoft.Web.ui.WebControls.treenode [] rootnodes = new Microsoft.Web.ui.WebControls.treenode [count];

For (int i = 0; i

#Region Private Void BindPermission () {// Binding Permissions String Info = String.empty; Microsoft.Web.ui.WebControls.treenodeCollection nodes = TreeView1.nodes;

IF (nodes.count> 0) {rg.jgj.modules.accounts.business.permission p = new rg.jgj.Modules.accounts.business.permission (); for (int i = 0; i

private void Button1_Click (object sender, System.EventArgs e) {foreach (Microsoft.Web.UI.WebControls.TreeNode node in TreeView1.Nodes) {//Response.Write(node.Text ":" node.NodeData "
"); Foreach (Microsoft.Web.ui.WebControls.treenode n in node.nodes) {if (n.checked == true) {// The following data is the result we want, the role is realized Generate // (((("N.Parent).nodeData is the ID //n.nodedata of the permissions category is the ID response.write ((Microsoft.Web.ui.WebControls.treenode) (n.parent) ) .NodeData ":" nodedata "
");}}}}}} I compiled the code, and achieve the expected purpose.

转载请注明原文地址:https://www.9cbs.com/read-80297.html

New Post(0)