{
//每向下一层,多一个缩入单位
i++;
dataview dvnodesets = new dataview(dtnodesets);
dvnodesets.rowfilter = strparentcolumn + "=" + strrootvalue;
string strpading = ""; //缩入字符
//通过i来控制缩入字符的长度,我这里设定的是一个全角的空格
for (int j = 0; j < i; j++)
strpading += " ";//如果要增加缩入的长度,改成两个全角的空格就可以了
foreach (datarowview drv in dvnodesets)
{
treenode tnnode = new treenode();
listitem li = new listitem(strpading + "├" + drv[strtextcolumn].tostring(), drv[strindexcolumn].tostring());
drpbind.items.add(li);
maketree(dtnodesets, strparentcolumn, drv[strindexcolumn].tostring(), strindexcolumn, strtextcolumn, drpbind, i);
}
//递归结束,要回到上一层,所以缩入量减少一个单位
i--;
}
/// <summary>
/// sql语句查询,再绑定到droplist里面
/// </summary>
private void createtree()
{
//查询zonelist
string sql = "select * from master_department where parent_department='003'";
dataset ds = db.getds();
datatable dt = ds.tables[0];
maketree(dt, "parent_department", "003", "department_code", "department_name", dropdownlist1, -1);
}
网上找的另一个比较好的实例
using system;
using system.collections.generic;
using system.text;
using system.web.ui.webcontrols;
namespace interface.common
{
public interface idropdowntree : idisposable
{
/**//// <summary>
/// 返回dictionary里分别对应id,文本,如果没有子节点返回null
/// </summary>
/// <param name="parentid">父节点id</param>
/// <returns></returns>
dictionary<string, string> getchildcategory(string parentid);
/**//// <summary>
/// 代码里写return new interface.common.dropdowntree(this);
/// </summary>
dropdowntree dropdowntree
{
get;
}
}
public sealed class dropdowntree
{
idropdowntree _dropdowntree;
public dropdowntree(idropdowntree dropdowntree)








