日期:2014-05-17  浏览次数:20520 次

关于Dtree,求详细解释,就剩下20分了
C# code

  protected string Url = "";//初始页url
    protected string tree = "";
    SqlServerDataBase obj = new SqlServerDataBase();
    string userid = "";
    string roleid = "";
    string areaid = "";
    string themes = "";
    DataSet ds = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Url = Request.QueryString["ul"];
            if (Session["ul"] == null || Session["ul"] == "")
            {
                Session["ul"] = Url;
            }
            else
            {
                if (Session["ul"] == Url)
                {
                    return;
                }
                else
                {
                    Session["ul"] = Url;
                }
            }

         
            BindSiteTree();
        }
    }

    private void BindSiteTree()
    {
        userid = Request.QueryString["sid"];

        string url1 = "", url2 = "";


        string Sql = "SELECT     cast(id as varchar) id,cast(parentid as varchar) parentid, sname,0 r,1 online FROM         UserGroup " +
            " union SELECT  cast(addr1 as varchar)+'$'+cast(addr2  as varchar)+'$'+cast(addr3  as varchar)id,cast(bumenid as varchar) bumenid ,  '('+cast(addr1 as varchar)+')'+name+'('+cast(addr2 as varchar)+')' name,1 r,online FROM         MonitorInfo  where addr3!=''";
        ds = obj.Select(Sql, null);

        Response.Write("<script type='text/javascript' src='../js/dtree/dtree_JS.js'></script> ");
        Response.Write("<script language='javascript'> d = new dTree('d');</script>");


        Response.Write("<script language='javascript'>d.add('000',-1,'全部');</script>");
        DataRow[] dcarea = ds.Tables[0].Select("parentid='0' ");


        foreach (DataRow dr in dcarea)
        {

            //Response.Write("<script language='javascript'>d.add('" + dr["id"].ToString() + "','000','" + dr["sname"].ToString() + "','../Tem_Index/Index_Elcharge.aspx?id=" + dr["id"].ToString() + "&th=" + Request.QueryString["th"] + "&fg=1','','main');</script>");
          //  Response.Write("<script language='javascript'>d.add('" + dr["id"].ToString() + "','" + dr["parentid"].ToString() + "','" + dr["sname"].ToString() + "',\"javascript:redir('" + dr["id"].ToString() + "','" + Request.QueryString["th"] + "','1')\");</script>");
            Response.Write("<script language='javascript'>d.add('" + dr["id"].ToString() + "','000','" + dr["sname"].ToString() + "',\"javascript:redir('" + dr["id"].ToString() + "','" + Request.QueryString["th"] + "','1')\");</script>");
            Child(dr["id"].ToString(), url1, url2);
        }
        Response.Write("<script language='javascript'>document.write(d);</script>");
    }
    public void Child(string parent, string url1, string url2)
    {
        DataRow[] drchild = ds.Tables[0].Select("parentid='" + parent + "'");
        if (drchild != null)
        {
            foreach (DataRow dr in drchild)
            {
                if (dr["r"].ToString() == "1")
                {
                    string name = "";
                    if (dr["online"].ToString() == "0")