在同一个下拉列表显示树形结构


    public string ResponseTypeTree(string nid)
    {
        StringBuilder sb = new StringBuilder(); ;
        DataTable dt = ClassManager.GetListByParentID("0");


        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.Append("<option value=\"\">├" + dt.Rows[i]["NodeName"].ToString() + "</option>");
            this.GetChildType(dt.Rows[i]["NodeID"].ToString(), ref sb, "", nid);
        }
        return (sb.ToString());

    }
    private void GetChildType(string id, ref StringBuilder rsb, string str1, string nid)
    {
        DataTable dt = ClassManager.GetListByParentID(id);
        if (dt.Rows.Count == 0)
            return;

        string imgstr = "";
        imgstr = str1 + "&nbsp;&nbsp;";
        //if (dt.Rows.Count > 0)
        //{
        //    imgsrt = "<img src=images/folderHR.gif width=18 height=18>";
        //}

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string val = "";
            if (dt.Rows[i]["NodeType"].ToString() == "0") val = dt.Rows[i]["NodeID"].ToString();

            rsb.Append("<option value=\"" + val + "\"");
            if (nid == dt.Rows[i]["NodeID"].ToString()) rsb.Append(" selected=\"selected\"");

            rsb.Append(">│" + imgstr + "└" + dt.Rows[i]["NodeName"].ToString() + "</option>");
            this.GetChildType(dt.Rows[i]["NodeID"].ToString(), ref rsb, imgstr, nid);
        }
    }

你可能感兴趣的:(下拉列表)