• 在DropDownList里显示多级分类


    protected void ddlBind()
            {
                DataTable dt = new DataTable();
                ddlCategoryId.DataSource = getList("0", dt);
                ddlCategoryId.DataTextField = "title";
                ddlCategoryId.DataValueField = "id";
                ddlCategoryId.DataBind();
                ddlCategoryId.Items.Insert(0, new ListItem("请选择类别", "-1"));
            }
    
            public DataTable getList(string pid, DataTable list)
            {
                BLL.article_category bll = new BLL.article_category();
                DataTable dt;
                if (pid == "0")
                {
                    dt = bll.GetList("parent_id='0'").Tables[0];
                    list = dt.Clone();
                }
                else
                {
                    dt = bll.GetList(" parent_id='" + pid + "'").Tables[0];
                }
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        int layer = Convert.ToInt32(row["class_layer"].ToString());//深度
                        string Title = row["title"].ToString().Trim();
                        if (layer > 1)
                        {
                            Title = "" + Title;
                            Title = StringOfChar(layer - 1, " ") + Title;
                        }
                        row["title"] = Title;
                        list.ImportRow(row);
                        getList(row["id"].ToString(), list);
                    }
                }
                return list;
            }
    /// <summary>
            /// 生成指定长度的字符串,即生成strLong个str字符串
            /// </summary>
            /// <param name="strLong">生成的长度</param>
            /// <param name="str">以str生成字符串</param>
            /// <returns></returns>
            public static string StringOfChar(int strLong, string str)
            {
                string ReturnStr = "";
                for (int i = 0; i < strLong; i++)
                {
                    ReturnStr += str;
                }
    
                return ReturnStr;
            }
    
    /// <summary>
            /// 获得数据列表
            /// </summary>
            public DataSet GetList(string strWhere)
            {
                StringBuilder strSql=new StringBuilder();
                strSql.Append("select * ");
                strSql.Append(" FROM article_category");
                if(strWhere.Trim()!="")
                {
                    strSql.Append(" where "+strWhere);
                }
                return OracleHelper.ExecuteDataset(strSql.ToString());
            }
     id title  parent_id  class_layer
     1  IT资讯  0   1
     2  IT业界  1  2

     

  • 相关阅读:
    斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时10
    斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时8&&9
    斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时7
    斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时6
    sprintf()函数用法
    openssl生成签名与验证签名
    PHP_EOL换行 与 base64编码
    grep配置颜色显示
    curl发送json格式数据
    sublime text3作为php开发IDE
  • 原文地址:https://www.cnblogs.com/liuswi/p/3956044.html
Copyright © 2020-2023  润新知