DropDownList中顯示無限級樹形結構

2021-09-06 16:57:25 字數 1374 閱讀 3438

效果圖:

資料庫表:

dirid:目錄的id,parentid:目錄的父路徑id,name:目錄的名字

主要**:

using system;

using system.collections;

using system.configuration;

using system.data;

using system.linq;

using system.web;

using system.web.security;

using system.web.ui;

using system.web.ui.htmlcontrols;

using system.web.ui.webcontrols;

using system.web.ui.webcontrols.webparts;

using system.xml.linq;

using system.data.sqlclient;

public partial class dropdownlisttree : system.web.ui.page

}/** 

/// 新增其他節點

/// 

/// 空格

/// 父路徑id

/// 返回的datatable

/// 樹形的深度

private void addotherdll(string pading, int dirid, datatable datatable,int deep)

//新增節點

listitem li = new listitem(strpading + "|--" + row["name"].tostring());

dropdownlist1.items.add(li);

//遞迴呼叫addotherdll函式,在函式中把deep加1

addotherdll(strpading,convert.toint32(row["dirid"]), datatable,deep+1);}}

/** 

/// 從資料庫中讀取資料返回datatable

/// 

/// 

private datatable getdatatable()}

當然,當讀取dropdownlist時若要去除"|--"和空格可以呼叫addotherdll.selectvalue().replace("|--","").trim()

遞迴在Dropdownlist中顯示樹狀結構

做專案的時候這種效果很多客戶覺得挺好的,挺直觀,但是實現呢有點技巧哈,有很多朋友問過我這個問題,今天我就把它貼出來 部分 返回分類列表 查詢條件 1為俄文,0為中文 public datatable gettype string querystr,string lflag else cols.add...

DropDownList實現樹形結構顯示

droplist.items.add list 注意區別 根節點 adddropdownlist droplist,int32.parse drv nodeid tostring trim list 遞迴 return droplist 計算當前節點深度 public int depth int n...

DropDownList的繫結與顯示問題

經常會遇到這種情況,dropdownlist控制項大部分用在繫結資料庫資料方面居多,但是常常要求它顯示在頁面上的的時候是乙個非資料庫中資料的內容,比如 請選擇 全部xx 等等,而實現這種功能的方法簡單不簡單我就不多說了,直接看源 吧!這裡假設要繫結的資料庫及欄位已經建好並確定 繫結資料庫欄位的 我就...