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

推荐订阅源

云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
小众软件
小众软件
Jina AI
Jina AI
The Cloudflare Blog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
G
GRAHAM CLULEY
Project Zero
Project Zero
博客园_首页
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
Latest news
Latest news
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
S
Securelist
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
IT之家
IT之家
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Last Watchdog
The Last Watchdog
T
Tenable Blog
宝玉的分享
宝玉的分享
S
Secure Thoughts
P
Privacy & Cybersecurity Law Blog
量子位
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Security Archives - TechRepublic
Security Archives - TechRepublic

博客园 - Steven Xiao

asp.net接收API Post Json数据为空要注意的事项 解决Asp.net 程序在 IIS 5.1 上运行不支持转换Decimal类型小数点的问题 - Steven Xiao 把XML 文件转换为 String 字符串 - Steven Xiao C#语言规范 3.0 版 分享DotNetBar控件制作office 2007风格界面的视频教程(winform office 2007 风格) XMLHttpRequest对象 SQL 2005实现单表分页的查询语句 分享实现web用户控件调用.aspx页面里的方法(从而达到访问母页面中控件的目的) 软件开发者面试百问 分享一个DotNetBar做的三层架构的winForm程序 分享一个不错的js提示信息代码(tooltips) - Steven Xiao - 博客园 asp.net 2.0实现多语言(二) asp.net 2.0实现多语言(一) 一个封装的在后台弹出JS Alert消息和JS confirm信息以及跳转到指定的页面 一个小小的WEB程序源代码 網絡收藏: 弹出窗口总结 - Steven Xiao gridview 实现全选和反选--补充 收藏的 sql经典语句 ---来自网上 ASP.NET button控件样式
dropdownlist实现树型结构的栏目信息
Steven Xiao · 2008-10-28 · via 博客园 - Steven Xiao

 如下图的效果: 

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = GetCategory().Tables[0];
            //绑定数据到栏目列表上
            BindToChannelList(dt, 0);

            }
        }

/// <summary>
        /// 递归绑定数据到ddlChannelList控件上,形成树状结构
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="categoryid">栏目id</param>
        private void BindToChannelList(DataTable dt, int categoryid)
        {

             //DataView dv = dt.DefaultView;使用这句在asp.net 1.1中会出现"在位置 1 处没有任何行。"的错误,感谢阿耀同学的帮助.

             DataView dv=new DataView(dt);
            
            dv.RowFilter = " ParentID= " + categoryid.ToString(); //过滤

            int layer = 0; //默认为第一层
            foreach (DataRowView drv in dv)
            {
                layer = int.Parse(drv["Layer"].ToString().Trim()); //取得第几层
                string span = "";
                if (categoryid != 0)
                {
                    for (int i = 0; i < layer; i++)
                    {
                        span += " ";
                    }
                    span += "|╴";//添加前面的空格
                }


                ListItem li = new ListItem();
                li.Text = span + drv["CategoryName"].ToString();
                li.Value = drv["CategoryID"].ToString();
                this.ddlChannelList.Items.Add(li);
                BindToChannelList(dt, Convert.ToInt32(drv["CategoryID"]));
            }
        }

----数据库表结构

CREATE TABLE [Category] (
 [CategoryID] [int] IDENTITY (1, 1) NOT NULL ,
 [CategoryName] [nvarchar] (255)  NOT NULL ,
 [Layer] [int] NULL  DEFAULT (1),
 [ParentID] [int] NULL  DEFAULT (0),
 [Intro] [nvarchar] (255)  NULL ,
 [AddTime] [datetime] NULL  DEFAULT (getdate()),
 CONSTRAINT [PK_Category] PRIMARY KEY  CLUSTERED
 (
  [CategoryID]
 )  ON [PRIMARY]
) ON [PRIMARY]
GO