码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET - 无限极分类

时间:2015-07-11 15:03:25      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

数据库设计:

 

-- 无限分类 --

-- 数据库:DB_InfiniteCategory

-- 数据表:Tb_Infinite

---------------------------------------------------------------

-- 创建数据库
CREATE DATABASE DB_InfiniteCategory

-- 创建数据表
USE DB_InfiniteCategory
CREATE TABLE Tb_Infinite
(
    id int not null,                        --子级
    pid int not null,                        --父级
    categoryName varchar(10) not null        --分类名称
)


--使用语句
select id, pid, categoryName from Tb_Infinite where pid = 0

 

 

 

 

代码:

 

 1 using System;
 2 using System.Web.UI;
 3 using System.Data;
 4 using System.Data.SqlClient;
 5 
 6 using DAL;
 7 using System.Web.UI.WebControls;
 8 
 9 namespace InfiniteCategory
10 {
11     public partial class Default : System.Web.UI.Page
12     {
13         string toadd = "";
14 
15         protected void Page_Load(object sender, EventArgs e)
16         {
17             if (!Page.IsPostBack)
18             {
19                 GetArticleCategory("0");
20             }
21         }
22 
23         public void GetArticleCategory(string pid)
24         {
25             SqlConnection conn = new SqlConnection(" server = HUANGFU-PC; database = DB_InfiniteCategory; integrated security = true");
26             string sql = "select id,categoryName from Tb_Infinite where pid=@pid";
27             SqlCommand cmd = new SqlCommand(sql, conn);
28             SqlParameter Pid = new SqlParameter("@pid", SqlDbType.Int);
29             Pid.Value = pid;
30             cmd.Parameters.Add(Pid);
31             conn.Open();
32             SqlDataReader sdr = cmd.ExecuteReader();
33             while (sdr.Read())
34             {
35                 this.DropDownList1.Items.Add(new ListItem(toadd + " " + sdr[1].ToString(), sdr[0].ToString()));
36                 toadd += "─┴";
37                 this.GetArticleCategory(sdr[0].ToString());
38                 toadd = toadd.Substring(0, toadd.Length - 2);
39             }
40             sdr.Close();
41             conn.Close();
42         }
43     }
44 }

 

 

 

最终效果:

技术分享

 

ASP.NET - 无限极分类

标签:

原文地址:http://www.cnblogs.com/KTblog/p/4638557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!