温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:简单无限级分类(表格、下拉列表)源码
当前文件:
SimpleUnlimitedClass/Default.aspx.cs[2K,2009-6-12 11:54:09],打开代码结构图
SimpleUnlimitedClass/Default.aspx.cs[2K,2009-6-12 11:54:09],打开代码结构图1///作者:魏宝辉 2
///网址:http://www.weibaohui.com 3
///版权所有,转载请注明 4
using System; 5
using System.Configuration; 6
using System.Data; 7
using System.Web; 8
using System.Web.Security; 9
using System.Web.UI; 10
using System.Web.UI.HtmlControls; 11
using System.Web.UI.WebControls; 12
using System.Web.UI.WebControls.WebParts; 13
using FTchina; 14
15
16
public partial class _Default : System.Web.UI.Page 17
{ 18
19
20
protected void Page_Load(object sender, EventArgs e) 21
{ 22
if (!IsPostBack) 23
{ 24
LoadList(); 25
} 26
} 27
28
/// <summary> 29
/// 加载整个分类表 30
/// </summary> 31
private void LoadList() 32
{ 33
litlist.Text = ""; 34
35
int MTcount = 0;//执行遍历的次数 36
//开始迭代加载 37
MakeTr("1", MTcount); 38
39
} 40
/// <summary> 41
/// 装配每一行 42
/// </summary> 43
/// <param name="id">上级ID</param> 44
/// <param name="count">迭代次数</param> 45
private void MakeTr(string id, int count) 46
{ 47
48
DataView dv = new DataView(shujuku.GetDataTable("select * from lanmu where parentid=" + id + " order by id asc")); 49
foreach (DataRowView drv in dv) 50
{ 51
//形成表格 52
litlist.Text += "<tr><td>" + MakeFelgefu(count) + drv["context"].ToString() + "</td><td>自身编号" + drv["id"].ToString() + ",上级编号" + id + "</td></tr>"; 53
54
//形成下拉列表 55
ListItem li = new ListItem(MakeFelgefu(count) + drv["context"].ToString(), drv["id"].ToString()); 56
ddllm.Items.Add(li); 57
58
//再次遍历 59
MakeTr(drv["id"].ToString(), count + 1); 60
61
} 62
63
} 64
/// <summary> 65
/// Make分隔符 66
/// </summary> 67
/// <param name="count"></param> 68
/// <returns></returns> 69
private string MakeFelgefu(int count) 70
{ 71
string Returnwords = string.Empty; 72
if (count == 0) 73
{ 74
Returnwords = ""; 75
} 76
77
else 78
{ 79
Returnwords = ("├").PadLeft(count, ' '); 80
} 81
return Returnwords; 82
} 83
84
85
86
87
88
protected void btnziok_Click(object sender, EventArgs e) 89
{ 90
string parentid = ddllm.SelectedValue.ToString(); 91
string context = txbzifl.Text; 92
string sql = "insert into lanmu (parentid,context) values(" + parentid + ",'" + context + "') "; 93
shujuku.ExecuteSql(sql); 94
LoadList();//更新列表 95
96
} 97
protected void btnroot_Click(object sender, EventArgs e) 98
{ 99
string context =txbroot.Text; 100
string sql = "insert into lanmu (parentid,context) values(1,'" + context + "') "; 101
shujuku.ExecuteSql(sql); 102
LoadList();//更新列表 103
104
} 105
}








}