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

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

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