ID |
ParentID |
Name |
Description |
编号 |
父编号 |
名称 |
说明 |
二、递归代码
说明:DataAccess—数据访问函数,传如SQL语句,返回DataTable
DListType---dropdownlist控件名称
private DataTable dtPowerTree = new DataTable();
dtPowerTree=DataAccess("select id,name,Description,parentid from type");
public void ddlset(string _ParentId,string strText)
{
strText += HttpUtility.HtmlDecode(" ");
string filter = "ParentId=" + _ParentId;
string sort = "id ASC";
DataRow[] drs = dtPowerTree.Select(filter, sort);
for(int i=0; i<drs.Length; i++)
{
if(drs[i][3].ToString() == _ParentId)
{
string Id = drs[i][0].ToString();
string Name = drs[i][1].ToString();
if(_ParentId!="0")
{
DListType.Items.Add(new ListItem(strText+"←"+Name,Id));
}
else
{
DListType.Items.Add(new ListItem(Name,Id));
}
ddlset(Id,strText);
}
}
}