All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
教你如何在Perl下连接Access数据库_php资料_编程技术
C#,DataGridView隔行显示不同的颜色_.net资料_编程技术
PHPUnit袖珍指南之命令行测试工具_php资料_编程技术
ASP.NET中文件上传下载方法集合_[Asp.Net教程]
让SQL Server为工作负载高峰提前做好准备_[SQL Server教程]
ASP.NET,2.0移动开发之属性重写和模板化_.net资料_编程技术
sql语句_mssql学习_编程技术
C#2.0基本语法二_[Asp.Net教程]
Silverlight,2,(beta1)数据操作(6)——使用LINQ,to,SQL进行数据_[Asp.Net教程]
卸载SQL Server2000后不能再次安装的问题解决方法_[SQL Server教程]
Reading number is top 10 pictures
Wear bikinis cock
From China fortress sora aoi4
泳装名模阿尔贝特妮写真
Beauty ZhiHuiLin2
七步解决性冷淡
The most popular girls welcome eggplant
超强高考作文
贩卖儿童者必须判死刑
Earthquake hedge common sense
The beginning and end
Download software ranking
徐若瑄成名作“魔鬼天使”
Unix video tutorial7
实战黑客不求人
Eclipse 4.2.2 For Win64
Eclipse 4.2.1 For Win32
WebService在.NET中的实战应用教学视频 → 第1集
Red cliff
Boxer Classic video1
致我们终将逝去的青春
网页特效实例大全
归海一刀 published in(发表于) 2014/1/30 1:01:31 Edit(编辑)
DropDownList无限级分类(灵活控制显示形式)_[Asp.Net教程]

DropDownList无限级分类(灵活控制显示形式)_[Asp.Net教程]

DropDownList无限级分类(灵活控制显示形式)_[Asp.Net教程]

DropDownList 实现无限级分类,主要使用递归实现,


数据库结构:


最终样式:


1protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!Page.IsPostBack)
4 {
5 BindDrpClass();
6 }
7 }
8 //绑定顶级分类
9 private void BindDrpClass()
10 {
11 Bll.Class classSystem = new Bll.Class();
12 DataTable dt = classSystem.GetClassList("").Tables[0];
13 ddlClass.Items.Clear();
14 ddlClass.Items.Add(new ListItem("添加根栏目","0"));
15 DataRow[] drs = dt.Select("ParentID= " + 0);
16
17 foreach (DataRow dr in drs)
18 {
19 string classid = dr["ClassID"].ToString();
20 string classname = dr["ClassName"].ToString();
21 //顶级分类显示形式
22 classname = "╋" + classname;
23
24 ddlClass.Items.Add(new ListItem(classname, classid));
25 int sonparentid = int.Parse(classid);
26 string blank = "├";
27 //递归子分类方法
28 BindNode(sonparentid, dt, blank);
29 }
30 ddlClass.DataBind();
31 }
32 //绑定子分类
33 private void BindNode(int parentid, DataTable dt, string blank)
34 {
35 DataRow[] drs = dt.Select("ParentID= " + parentid);
36
37 foreach (DataRow dr in drs)
38 {
39 string classid = dr["ClassID"].ToString();
40 string classname = dr["ClassName"].ToString();
41
42 classname = blank + classname;
43 ddlClass.Items.Add(new ListItem(classname, classid));
44
45 int sonparentid = int.Parse(classid);
46 string blank2 = blank + "─";
47
48 BindNode(sonparentid, dt, blank2);
49 }
50 }
数据访问(Bll里面的classSystem方法 )
1public DataSet GetClassList(string strWhere)
2 {
3 StringBuilder strSql = new StringBuilder();
4 strSql.Append("select * from tb_Class ");
5 if (strWhere.Trim() != "")
6 {
7 strSql.Append(" where " + strWhere);
8 }
9 return SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, strSql.ToString());
10 }


来源:http://www.cnblogs.com/chensubo







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.