private DataTable dtPowerTree = new DataTable(); const string tablename = " tree " ; private void Page_Load( object sender, System.EventArgs e) ... { FillTreeDataTable(); blTreeDataTable(0); dtPowerTree.Clear(); // 在此处放置用户代码以初始化页面 } private void FillTreeDataTable() ... { string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; SqlConnection conn = new SqlConnection(ConnectionString); SqlDataAdapter da = new SqlDataAdapter("select Id,PowerName,Layer,ParentId from " + tablename, conn); da.Fill(dtPowerTree); } private void blTreeDataTable( int _ParentId) ... { string filter = "ParentId=" + _ParentId; string sort = "Id ASC"; DataRow[] drs = dtPowerTree.Select(filter, sort); for(int i=0; i<drs.Length; i++) ...{ if(Convert.ToInt32(drs[i][3]) == _ParentId) ...{ int Id = Convert.ToInt32(drs[i][0]); string PowerName = drs[i][1].ToString(); int Layer = Convert.ToInt32(drs[i][2]); for(int space=1; space<=Layer; space++) ...{ Page.Response.Write(" "); } Page.Response.Write(PowerName + "<br>"); blTreeDataTable(Id); } } }