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

推荐订阅源

L
LangChain Blog
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Stack Overflow Blog
Stack Overflow Blog
Forbes - Security
Forbes - Security
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
S
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
N
News | PayPal Newsroom
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
Vercel News
Vercel News
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Google Online Security Blog
Google Online Security Blog
Simon Willison's Weblog
Simon Willison's Weblog
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
T
Tenable Blog
I
InfoQ
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
D
DataBreaches.Net
博客园 - Franky
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
S
Security @ Cisco Blogs
Hacker News: Ask HN
Hacker News: Ask HN
J
Java Code Geeks
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Full Disclosure
C
Cisco Blogs
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Cloudflare Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
I
Intezer
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs
Jina AI
Jina AI
V
Visual Studio Blog
L
LINUX DO - 热门话题
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏

博客园 - Ferry

ASP.NET网站权限设计实现(三)——套用JQuery EasyUI列表显示数据、分页、查询 ASP.NET网站权限设计实现(二)——角色权限绑定 ASP.NET读取网络图片并在页面上显示 ASP.NET网站权限设计实现(一)——使用PowerDesigner进行数据库设计 Visual Studio 2010 架构图之用例图(UML Use Case Diagram) ASP.NET MVC3 新的视图引擎(View Engine) 一个德国人图解中西文化差异(值得一看) 微软AJAX CDN(内容分发网络) 注册使用GAC—Global Assembly Cache(.NET) 新浪微博PC客户端(DotNet WinForm版)——功能实现分解介绍 新浪微博PC客户端(DotNet WinForm版)—— 初探 C#:30行数据插入到数据库中的效率测试-一行行执行、构造SQL一次执行、SqlBulkCopy C#使用GMAIL群发带附件邮件的例子 ASP.NET Web 应用开发实战快速上手系列 3—C#面向对象编程纲要-类 ASP.NET带进度条多文件上传 ASP.NET4.0中客户端ID的生成 在高优先级下运行应用程序 学习使用NHibernate2.1.0Beta1(续七)— 单例模式 ASP.NET Web 应用开发实战快速上手系列 2——C#基础
ASP.NET 递归将分类绑定到 TreeView - Ferry
Ferry · 2010-12-14 · via 博客园 - Ferry

CREATE TABLE [dbo].[sysMenuTree](
[NoteId] [decimal](180NOT NULL,
[ParentId] [decimal](180NULL,
[sText] [nvarchar](50NULL,
[sValue] [nvarchar](50NULL,
[sURL] [nvarchar](50NULL,
[sTarget] [nvarchar](50NULL,
[Chger] [nvarchar](50NULL,
[ChgTime] [nvarchar](50NULL,
 
CONSTRAINT [PK_sysMenuTree] PRIMARY KEY CLUSTERED  
(
[NoteId] ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ONON [PRIMARY]
ON [PRIMARY]insert into sysMenuTree values(3,0,N'目錄',N'目錄','','','','')
insert into sysMenuTree values(4,0,N'目錄',N'目錄','','','','')
insert into sysMenuTree values(5,0,N'目錄',N'目錄','','','','')
insert into sysMenuTree values(6,3,N'項目.1',N'項目.1','','','','')
insert into sysMenuTree values(7,3,N'項目.2',N'項目.2','','','','')
insert into sysMenuTree values(8,4,N'項目.1',N'項目.1','','','','')
insert into sysMenuTree values(9,4,N'項目.2',N'項目.2','','','','')
insert into sysMenuTree values(10,4,N'項目.3',N'項目.3','','','','')
insert into sysMenuTree values(11,5,N'項目.1',N'項目.1','','','','')
insert into sysMenuTree values(12,5,N'項目.2',N'項目.2','','','','')

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title></title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:TreeView ID="treeMenu" runat="server">
        
</asp:TreeView>
    
</div>
    
</form>
</body>
</html>

using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
{
    
private readonly string ConnString = @"server=.\MSSQLSERVER2008;database=chart;uid=sa;pwd=123456";
    
private DataTable dt = null;
    
protected void Page_Load(object sender, EventArgs e)
    {
        
if(!IsPostBack)
        {
            dt 
= new DataTable();
            GetMenuToDataTable(
"select * from sysMenuTree",dt);
            BindTree(dt,
null,"0");
        }
    }
private void BindTree(DataTable dtSource,TreeNode parentNode,string parentID)
    {
        DataRow[] rows 
= dtSource.Select(string.Format("ParentID={0}",parentID));
        
foreach(DataRow row in rows)
        {
            TreeNode node 
= new TreeNode();
            node.Text 
= row["sText"].ToString();
            node.Value 
= row["sValue"].ToString();
            BindTree(dtSource,node,row[
"NoteId"].ToString());
            
if(parentNode ==  null)
            {
                treeMenu.Nodes.Add(node);
            }
            
else
            {
                parentNode.ChildNodes.Add(node);
            }
        }
    }
private DataTable GetMenuToDataTable(string query,DataTable dt)
    {
        
using(SqlConnection conn = new SqlConnection(ConnString))
        {
            SqlCommand cmd 
= new SqlCommand(query,conn);
            SqlDataAdapter ada 
= new SqlDataAdapter(cmd);
            ada.Fill(dt);
        }
        
return dt;
    }
}