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

推荐订阅源

博客园 - 【当耐特】
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
小众软件
小众软件
The Cloudflare Blog
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
美团技术团队
WordPress大学
WordPress大学
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
GbyAI
GbyAI
B
Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗

博客园 - 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;
    }
}