using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Web;
namespace HuaenCms.Inc
{
    public class shareclass
    {
        public static int tempnums = 0, htemp_parentid = 0;
        public shareclass()
        {

        }
        /// <summary>
        /// 栏目选择Select
        /// </summary>
        /// <param name="parentid"></param>
        /// <param name="selectedid"></param>
        /// <returns></returns>
        public static string ParentColumnSelectBox(int parentid, int selectedid)
        {
            StringBuilder html = new StringBuilder();
            html.Append("<select name=\"txtParentId\" id=\"txtParentId\" size=\"1\" style=\"float:left\">");
            html.Append("<option value=\"0\">选择栏目</option>");
            html.Append(GetColumnOptionsList(parentid, selectedid));
            html.Append("</select>");
            return html.ToString();
        }
          /// <summary>
        /// 树形栏目
        /// </summary>
        /// <param name="parentid"></param>
        /// <param name="selectedid"></param>
        /// <returns></returns>
        public static string GetColumnOptionsList(int parentid, int selectedid)
        {
            HuaenCms.BLL.cms_column cbll = new HuaenCms.BLL.cms_column();
            StringBuilder html = new StringBuilder();
            DataTable dt = cbll.GetList(0, "ParentId=" + parentid, "Listorder asc").Tables[0];
            GetColumnLevel2(parentid);
            //Response.Write(tempnums);
            string tempstr = "";
            if (parentid == 0)
            {
                tempstr = "";
            }
            else
            {
                for (int dex = 0; dex < tempnums; dex++)
                {
                    tempstr += "&nbsp;&nbsp;&nbsp;├";
                }
            }
            foreach (DataRow dr in dt.Rows)
            {
                int columnid = int.Parse(dr["RecordId"].ToString());
                if (columnid == selectedid)
                {
                    html.Append("<option value=" + dr["RecordId"].ToString() + " selected>" + tempstr + dr["ColumnName"].ToString() + "</option>");
                }
                else
                {
                    html.Append("<option value=" + dr["RecordId"].ToString() + ">" + tempstr + dr["ColumnName"].ToString() + "</option>");
                }
                tempnums = 0;
                html.Append(GetColumnOptionsList(columnid, selectedid));
            }
            return html.ToString();
        }

        /// <summary>
        /// 获取栏目分类级别
        /// </summary>
        /// <param name="parentid"></param>
        public static void GetColumnLevel2(int parentid)
        {
            if (int.Parse(DbHelperSQL.GetSingle("select count(RecordId) from cms_column where RecordId=" + parentid).ToString()) > 0)
            {
                if (parentid != htemp_parentid)
                {
                    tempnums += 1;
                    htemp_parentid = parentid;
                }
                int temp_parentid = int.Parse(Maticsoft.DBUtility.DbHelperSQL.GetSingle("select  parentid from cms_column where RecordId=" + parentid).ToString());
                if (temp_parentid > 0)
                {
                    GetColumnLevel2(temp_parentid);
                }
            }
        } 
 }
 

二、调用示例

Response.Write(ParentColumnSelectBox(0,0));