素材巴巴 > 程序开发 >

无限级遍历树(递归)

程序开发 2023-09-13 11:48:05
转自: http://www.iteye.com/topic/1122691

C# 中遍历树 ajax读取数据 递归算法实现数据树结构输出 
数据表格字段为:id,Name,pID(父级ID) 
js代码 
Javascript代码

 
服务器端C#代码 
C#代码
    public DataTable GetChildren(int id){//string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SiteConnectionString"].ConnectionString;//string strCon = "Data Source=.;Integrated Security=SSPI;Initial Catalog=test";string strCon = "server=.;database=test;Integrated Security=sspi";using (SqlConnection conn = new SqlConnection(strCon)){using (SqlCommand cmd = conn.CreateCommand()){cmd.CommandText = "select  id, Name,pID from tab_Tree where pID=" + id;conn.Open();cmd.CommandType = CommandType.Text;SqlDataAdapter dbA = new SqlDataAdapter(cmd);DataSet ds = new DataSet();dbA.Fill(ds);conn.Close();return ds.Tables[0];}}}
 

附件为我写的测试项目





标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。