dropdownlist树形菜单

从网上找到的树形DropDownList例子,但发现只能显示两级,能帮我改成无限级别显示吗!!
另外在节点上再增加个判断如果是末尾显示└,否则显示├!!

public void Page_Load(object sender,EventArgs e)
  {
   if(!IsPostBack)
    DataListDataBind();
  }
  public void DataListDataBind()
  {
   SqlConnection myconn=new SqlConnection(ConfigurationSettings.AppSettings["connectionstring"].ToString());
   SqlDataAdapter da=new SqlDataAdapter("select BigClass_id,BigClass_name from BigClass where parentID=0",myconn);   //获取一级节点
   DataTable mytable=new DataTable();
   try
   {
    da.Fill(mytable);
    ArrayList nameList = new ArrayList();
    for(int i=0;i<mytable.Rows.Count;i++)
    {
     nameList.Add("|--"+mytable.Rows[i]["BigClass_name"].ToString());
     string id=mytable.Rows[i]["BigClass_id"].ToString();
     SqlConnection myconn1=new SqlConnection(ConfigurationSettings.AppSettings["connectionstring"].ToString());
     SqlDataAdapter da1=new SqlDataAdapter("select SmalClass_name from SmalClass where BigClass_id='"+id+"'",myconn1);  //获取二级节点
     DataTable mytable1=new DataTable();
     da1.Fill(mytable1);
     for(int j=0;j<mytable1.Rows.Count;j++)
      nameList.Add("│├"+mytable1.Rows[j]["SmalClass_name"].ToString());

    }
    Drop1.DataSource=nameList;
    Drop1.DataBind();

   }
   catch(Exception error)
   {
    Response.Write(error.ToString());
   }
  }

posted @ 2006-10-27 17:16  '.Elvis.'  阅读(702)  评论(0编辑  收藏  举报