惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - Hm

敏捷开发中asp.net mvc3编写的正确顺序 WF4.0入门系列2——用代码创建一个简单的工作流 WF4.0入门系列 WF4.0入门系列1——创建一个简单的工作流 C#解析xml代码 - Hm - 博客园 什么是依赖注入 找不到可安装的ISAM错误 - Hm - 博客园 ASP.NET下用相对路径访问ACCESS数据解决方案 使vs2008支持extjs智能提示功能 VS2005文件自动定位功能 微软VSTS 2005 试用版注册为正式版的方法 敏捷开发感悟 敏捷开发笔记(二) 敏捷开发笔记(一) VS 2008 and .NET 3.5 Beta 2 发布了 得到本机的IP地址和MAC地址的工具类 DWR简介 WebWork Processors Then and Now
动态权限树控件
Hm · 2007-07-17 · via 博客园 - Hm

后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class control_TreeViewControl : System.Web.UI.UserControl
{
    private int opclass = 1;//默人权限最小为个人
    /// <summary>
    /// 修改opclass的属性
    /// </summary>
    public int Opclass
    {
        get { return opclass; }
        set { opclass = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Opclass = Session["OptClass"].ToString();//从session中取得权限
        if (!IsPostBack)
        {
            TreeNode trObj = new TreeNode("首页", "00");
            trObj.NavigateUrl = "../Default.aspx";
            //trObj.Target = "main";
            trObj.PopulateOnDemand = true;//动态填充设置为true
            TreeViewlist.Nodes.Add(trObj);
        }
    }

    private void PopulateFirst(TreeNode node)
    {
        // Query for the product categories. These are the values
        // for the second-level nodes.
        DataSet ResultSet = RunQuery("Select ModuleName,ModuleID From fn_visit_table(" + opclass + ") Where len(ModuleID)=3 and ModuleId like '21_'");//加载一级菜单
        // Create the second-level nodes.
        if (ResultSet.Tables.Count > 0)
        {
            // Iterate through and create a new node for each row in the query results.
            // Notice that the query results are stored in the table of the DataSet.
            foreach (DataRow row in ResultSet.Tables[0].Rows)
            {
                // Create the new node. Notice that the CategoryId is stored in the Value property
                // of the node. This will make querying for items in a specific category easier when
                // the third-level nodes are created.
                TreeNode newNode = new TreeNode();
                newNode.Text = row["ModuleName"].ToString();
                newNode.Value = row["ModuleID"].ToString();
                // Set the PopulateOnDemand property to true so that the child nodes can be
                // dynamically populated.
                newNode.PopulateOnDemand = true;
                // Set additional properties for the node.
                newNode.SelectAction = TreeNodeSelectAction.Expand;
                // Add the new node to the ChildNodes collection of the parent node.
                node.ChildNodes.Add(newNode);
            }
        }
    }
    private void PopulateSecond(TreeNode node)
    {
        // Query for the products of the current category. These are the values
        // for the third-level nodes.
        DataSet ResultSet = RunQuery("Select ModuleName,ModuleID,Remark From fn_visit_table(" + opclass + ")" +
            " Where len(ModuleID)=5 and substring(convert(char(8),ModuleID),1,3)='" + node.Value + "'");//加载二级菜单
        // Create the third-level nodes.
        if (ResultSet.Tables.Count > 0)
        {
            // Iterate through and create a new node for each row in the query results.
            // Notice that the query results are stored in the table of the DataSet.
            foreach (DataRow row in ResultSet.Tables[0].Rows)
            {
                // Create the new node.
                TreeNode newNode = new TreeNode();
                newNode.Text = row["ModuleName"].ToString();
                newNode.Value = row["ModuleID"].ToString();
                newNode.NavigateUrl = row["Remark"].ToString();
                // Set the PopulateOnDemand property to false, because these are leaf nodes and
                // do not need to be populated.
                newNode.PopulateOnDemand = true;
                // Set additional properties for the node.
                newNode.SelectAction = TreeNodeSelectAction.Expand;
                // Add the new node to the ChildNodes collection of the parent node.
                node.ChildNodes.Add(newNode);
            }
        }
    }

    private void PopulateThird(TreeNode node)
    {
        // Query for the products of the current category. These are the values
        // for the third-level nodes.
        DataSet ResultSet = RunQuery("Select ModuleName,ModuleID,Remark From fn_visit_table(" + opclass + ")" +
            " Where len(ModuleID)=8 and substring(convert(char(8),ModuleID),1,5)='" + node.Value + "'");////加载三级菜单
        // Create the third-level nodes.
        if (ResultSet.Tables.Count > 0)
        {
            // Iterate through and create a new node for each row in the query results.
            // Notice that the query results are stored in the table of the DataSet.
            foreach (DataRow row in ResultSet.Tables[0].Rows)
            {
                // Create the new node.
                TreeNode newNode = new TreeNode();
                newNode.Text = row["ModuleName"].ToString();
                newNode.Value = row["ModuleID"].ToString();
                newNode.NavigateUrl = row["Remark"].ToString();
                // Set the PopulateOnDemand property to false, because these are leaf nodes and
                // do not need to be populated.
                newNode.PopulateOnDemand = false;
                // Set additional properties for the node.
                newNode.SelectAction = TreeNodeSelectAction.Expand;//
                // Add the new node to the ChildNodes collection of the parent node.
                node.ChildNodes.Add(newNode);
            }
        }
    }
    private DataSet RunQuery(String QueryString)
    {
        String ConnectionString = ConfigurationManager.ConnectionStrings["MISDBConnectionString"].ToString();
        SqlConnection DBConnection = new SqlConnection(ConnectionString);
        SqlDataAdapter DBAdapter;
        DataSet ResultsDataSet = new DataSet();
        try
        {
            //运行查询和创建DataSet
            DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
            DBAdapter.Fill(ResultsDataSet);
            DBConnection.Close();//关闭连接
        }
        catch
        {
            // 异常处理如果连接没有关闭,则关闭连接.
            if (DBConnection.State == ConnectionState.Open)
            {
                DBConnection.Close();
            }
            throw new Exception();
        }
        return ResultsDataSet;
    }
    protected void tvClass_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
        // Call the appropriate method to populate a node at a particular level.
        int myTemp = e.Node.Depth;
        switch (myTemp)
        {
            case 0:
                // 装载第一层节点
                PopulateFirst(e.Node);
                break;
            case 1:
                // 装载第二层节点
                PopulateSecond(e.Node);//PopulateSecond
                break;
            case 2:
                // 装载第三层节点
                PopulateThird(e.Node);
                break;
            default:
                // Do nothing.
                break;
        }
    }
}
前台代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TreeViewControl.ascx.cs" Inherits="control_TreeViewControl" %>
<asp:TreeView ID="TreeViewlist" runat="server" OnTreeNodePopulate="tvClass_TreeNodePopulate" CssClass="menutextindent" SkinID="TreeView">
</asp:TreeView>
效果图: