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

推荐订阅源

Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
S
Securelist
P
Proofpoint News Feed
H
Help Net Security
S
Schneier on Security
T
Tenable Blog
C
Cisco Blogs
S
Security @ Cisco Blogs
博客园 - 司徒正美
博客园 - 叶小钗
Cisco Talos Blog
Cisco Talos Blog
Google DeepMind News
Google DeepMind News
C
Cybersecurity and Infrastructure Security Agency CISA
Google Online Security Blog
Google Online Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hacker News: Ask HN
Hacker News: Ask HN
NISL@THU
NISL@THU
云风的 BLOG
云风的 BLOG
V
Vulnerabilities – Threatpost
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
W
WeLiveSecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Jina AI
Jina AI
腾讯CDC
WordPress大学
WordPress大学
Simon Willison's Weblog
Simon Willison's Weblog
Vercel News
Vercel News
小众软件
小众软件
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
雷峰网
雷峰网
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
博客园 - 聂微东
F
Full Disclosure
量子位
Scott Helme
Scott Helme
宝玉的分享
宝玉的分享
A
About on SuperTechFans
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Schneier on Security
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
Kaspersky official blog
AI
AI
SecWiki News
SecWiki News
Webroot Blog
Webroot Blog
Martin Fowler
Martin Fowler

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