现在的位置: 首页 > 综合 > 正文

Dropdownlist中实现树行选择

2011年03月14日 ⁄ 综合 ⁄ 共 952字 ⁄ 字号 评论关闭
一、数据结构

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);

            }

    }

}

抱歉!评论已关闭.