c#無線迴圈出樹形導航 ,可摺疊,有勾選

來源:互聯網
上載者:User

標籤:摺疊導航   樹形導航   無線迴圈   

輸出結果

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4D/8E/wKiom1RTLm_gfOQqAABSmIgU93s234.jpg" title="QQ20141031143730.jpg" alt="wKiom1RTLm_gfOQqAABSmIgU93s234.jpg" />

表結構 

depid depname upid//所屬上級id xh //排序 正序
123 一級導航 0  // 一級 0
124 一級下二級導航 123 1

c#  代碼:

 public string showdep()//輸出第一層,根據所屬上級id調用下一層

    {

        string str = "";

        DataTable dep = getdep(0, "");

        int ii = 0;

        foreach (System.Data.DataRow dt1 in dep.Rows)

        {

            str += " <li>  <input type=\"checkbox\" id=\"Depds\" name=\"Dep" + ii + "\" alt=\"" + dt1["depid"].ToString() + "\" ";

            str += " onClick=\"chkbm(" + ii + ",‘" + dt1["depid"].ToString() + " ‘)\" value=\"" + dt1["depid"].ToString() + "\"" + PowerCheck.Depsge(dt1["depid"].ToString()) + "  />";

            str += dt1["depName"].ToString();

            str += "</li>";

            DataTable dep1 = getdep(int.Parse(dt1["depid"].ToString()), "&nbsp;&nbsp;&nbsp;|-");

            str += showdep1(dep1, "|-");

            ii++;

        }


        return str;

    }

    public DataTable getdep(int upid, string shu)

    {//shu欄位 放在最前面輸出 可看出層次, 但此次指令碼已控制層次,so此次沒用上

        string sql = "select depid,depname,upid,‘" + shu + "‘ as shu from depart where upid=" + upid + " order by xh asc ";

        DataTable dt = dbc.spdataset(sql).Tables[0];

        return dt;

    }

   

    public string showdep1( DataTable dt, string shu)

    {

        string str="";

        if (dt.Rows.Count > 0)

        {

            shu = "&nbsp;&nbsp;&nbsp;&nbsp;" + shu;

            int ii = 0;

            str += "<ul>";

            foreach (System.Data.DataRow dt1 in dt.Rows)

            {

                str += " <li><input type=\"checkbox\" id=\"Depds\" name=\"Dep" + ii + "\" alt=\"" + dt1["depid"].ToString() + "\" ";

                str += " onClick=\"chkbm(" + ii + ",‘" + dt1["depid"].ToString() + " ‘)\" value=\"" + dt1["depid"].ToString() + "\"" + PowerCheck.Depsge(dt1["depid"].ToString()) + "  />";

                str += dt1["depName"].ToString();

                str += "</li>";

                

                DataTable dep1 = getdep(int.Parse(dt1["depid"].ToString()), shu);

                str += showdep1(dep1, shu);

                ii++;

            }

            str += "</ul>";

        }

        return str;

    }

前台html代碼

引用樹形摺疊js, 把打鉤項的id逗號分隔存到一個輸入框裡 方便後台讀取


c#無線迴圈出樹形導航 ,可摺疊,有勾選

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.