温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:无限级树形(三层开发)源码
当前文件:
ClassTree/WebUI/ddl.aspx.cs[1K,2009-6-12 11:36:01],打开代码结构图
ClassTree/WebUI/ddl.aspx.cs[1K,2009-6-12 11:36:01],打开代码结构图1using System; 2
using System.Collections; 3
using System.Configuration; 4
using System.Data; 5
using System.Linq; 6
using System.Web; 7
using System.Web.Security; 8
using System.Web.UI; 9
using System.Web.UI.HtmlControls; 10
using System.Web.UI.WebControls; 11
using System.Web.UI.WebControls.WebParts; 12
using System.Xml.Linq; 13
using System.Data.SqlClient; 14
//该源码下载自www.51aspx.com(51aspx.com) 15
16
public partial class ddl : System.Web.UI.Page 17
{ 18
protected void Page_Load(object sender, EventArgs e) 19
{ 20
if (!Page.IsPostBack) 21
{ 22
this.GetArticleCategory("0"); 23
} 24
25
} 26
string toadd = "├"; 27
private void GetArticleCategory(string pid) 28
{ 29
//这里也要修改数据库连接信息并编译 30
string connectionString="Data Source=.;Initial Catalog=classTree;User ID=sa;pwd=sa;"; 31
SqlConnection conn = new SqlConnection(connectionString); 32
string sql = "select * from classTree where parentId="+pid; 33
SqlCommand cmd = new SqlCommand(sql, conn); 34
SqlParameter parentID = new SqlParameter("@parentID", SqlDbType.Int); 35
parentID.Value = pid; 36
conn.Open(); 37
SqlDataReader sdr = cmd.ExecuteReader(); 38
while (sdr.Read()) 39
{ 40
this.DropDownList1.Items.Add(new ListItem(toadd+" "+sdr["className"].ToString(),sdr["id"].ToString())); 41
toadd += "─┴"; 42
this.GetArticleCategory(sdr["id"].ToString()); 43
toadd = toadd.Substring(0, toadd.Length - 2); 44
} 45
sdr.Close(); 46
conn.Close(); 47
48
} 49
} 50






}
}