我在.cs中写了一个实现树型目录showTree()。
将生成的html代码赋给了一个变量strTree
怎样才能在.aspx页面中显示该目录。

解决方案 »

  1.   

    看不懂什么意思.
    Lable1.Text = strTree ; ?
      

  2.   

    变量定义为 public 访问级别
    aspx中写
    在页面里写  <%=变量名%>或者在页面里放一个label控件
    cs 中写
    label1.Text = 变量名;
      

  3.   

    label1.Text = 变量名;
    我试过,好象不能显示图片吧<%=变量名%>也是一片空白
      

  4.   

    public string strTree;
    ...
    ...
    <%=strTree%>
      

  5.   

    private string ShowTree()
    {
    string ConnSql1="";       
    string ConnSql2="";         
    string ConnSql3=""; 
    string ConnSql4=""; 
    ConnSql1="select departmentid,departmentName from Departments where ParentID='' order by departmentid";
    DataSet RsCatalog1=new DataSet ();
    RsCatalog1=Dbc.getBinding (ConnSql1,"s"); strTree="<div style='cursor:hand'>";
    if (RsCatalog1.Tables[0].Rows.Count>0)
    {
    for (int i=1;i<=RsCatalog1.Tables[0].Rows.Count;i++)
    {
    ConnSql2="select departmentid,departmentName from Departments where ParentID='"+RsCatalog1.Tables[0].Rows [i]["departmentid"] +"' order by departmentid";
    DataSet RsCatalog2=new DataSet ();
    RsCatalog2=Dbc.getBinding (ConnSql2,"s");
    if (RsCatalog2.Tables[0].Rows.Count>0)
    {
    strTree=strTree+"<span height=40 ID='Grades"+i+"' CLASS='Outline' title='"+RsCatalog1.Tables[0].Rows [i]["departmentName"]+"'>&nbsp;&nbsp;<IMG SRC='../images/folder.gif' border=0 ID='Grades"+i+"dd' WIDTH='16' HEIGHT='16'>"+RsCatalog1.Tables[0].Rows [i]["departmentName"]+"<br></span>";
    strTree=strTree+"<DIV ID=Grades"+i+"d  STYLE='display:none' CLASS='hide'>";
    for (int j=1;j<=RsCatalog2.Tables[0].Rows.Count;j++)
    {
    ConnSql3="select departmentid,departmentName from Departments where ParentID='"+RsCatalog2.Tables[0].Rows [j]["departmentid"] +"' order by departmentid";
    DataSet RsCatalog3=new DataSet ();
    RsCatalog3=Dbc.getBinding (ConnSql3,"s");
    if (RsCatalog3.Tables[0].Rows.Count>0)  
    {
    strTree=strTree+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span height=40 ID='Gradesj"+i+j+"' CLASS='Outline' title='"+RsCatalog2.Tables[0].Rows [j]["departmentName"]+"'>&nbsp;<IMG SRC='../images/folder.gif'ID='Gradesj"+i+j+"dd' WIDTH='16' HEIGHT='16'>"+RsCatalog2.Tables[0].Rows [j]["departmentName"]+"</span><br>";
    strTree=strTree+"<DIV ID=Gradesj"+i+j+"d  STYLE='display:none' CLASS='hide'>";
    for (int k=1;k<=RsCatalog3.Tables[0].Rows.Count;k++)
    {
    ConnSql4="select departmentid,departmentName from Departments where ParentID='"+RsCatalog3.Tables[0].Rows [k]["departmentid"] +"' order by departmentid";
    DataSet RsCatalog4=new DataSet ();
    RsCatalog4=Dbc.getBinding (ConnSql4,"s");
    if (RsCatalog4.Tables[0].Rows.Count>0)
    {
    strTree=strTree+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span height=40 ID='Gradesk"+i+j+k+"' CLASS='Outline' title='"+RsCatalog3.Tables[0].Rows [k]["departmentName"]+"'>&nbsp;<IMG SRC='../images/folder.gif' ID='Gradesk"+i+j+k+"dd' WIDTH='16' HEIGHT='16'>"+RsCatalog3.Tables[0].Rows [k]["departmentName"]+"</span><br>";
    strTree=strTree+"<DIV ID=Gradesk"+i+j+k+"d  STYLE='display:none' CLASS='hide'>";
    for (int l=1;l<=RsCatalog4.Tables[0].Rows.Count;l++)
    {
    strTree=strTree+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span height=40><IMG SRC='../images/htmlicon.gif' WIDTH='10' HEIGHT='10'>&nbsp;<a href=../sec_page/show.asp?subID="+RsCatalog4.Tables[0].Rows [l]["departmentid"]+" target=rightframe title='"+RsCatalog4.Tables[0].Rows [l]["departmentName"]+"'>"+RsCatalog4.Tables[0].Rows [l]["departmentName"]+"</a></span><br>";
    strTree=strTree+"</div>";
    }
    }
    else
    {
    strTree=strTree+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span height=40>&nbsp;&nbsp;&nbsp;<IMG SRC='../images/htmlicon.gif' WIDTH='10' HEIGHT='10'>&nbsp;<a href=../sec_page/show.asp?subID="+RsCatalog3.Tables[0].Rows [k]["departmentid"]+" target=rightframe title='"+RsCatalog3.Tables[0].Rows [k]["departmentName"]+"'>"+RsCatalog3.Tables[0].Rows [k]["departmentName"]+"</a></span><br>";
      
    } //RsCatalog4.close:Set RsCatalog4=Nothing     
    }
    strTree=strTree+"</div>";
    }
    else
    {
    strTree=strTree+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span height=40><IMG SRC='../images/htmlicon.gif' WIDTH='10' HEIGHT='10'>&nbsp;<a href=../sec_page/show.asp?subID="+RsCatalog2.Tables[0].Rows [j]["departmentid"]+" target=rightframe title='"+RsCatalog2.Tables[0].Rows [j]["departmentName"]+"'>"+RsCatalog2.Tables[0].Rows [j]["departmentName"]+"</a></span><br>";
    } //RsCatalog3.Close:Set RsCatalog3=Nothing
    }
    strTree=strTree+"</div>";
    }
    else
    {
    strTree=strTree+"&nbsp;&nbsp;<span height=40><IMG SRC='../images/htmlicon.gif' ID='Grades"+i+"' WIDTH='10' HEIGHT='10'>"+"&nbsp;<a href=../sec_page/show.asp?subID="+RsCatalog1.Tables[0].Rows [i]["departmentid"]+" target=rightframe title='"+RsCatalog1.Tables[0].Rows [i]["departmentName"]+"'>"+RsCatalog1.Tables[0].Rows [i]["departmentName"]+"</a></span><br>";
    } //RsCatalog2.Close:Set RsCatalog2=Nothing
    }
    }
    else
    {
    strTree=strTree+"<font color=red><b></b></font>";
    }
    strTree=strTree+"</div>";
    //RsCatalog1.Close:Set RsCatalog1=Nothing
    //this.LoadTemplate =strTree;
    return strTree;

    }
      

  6.   

    大家帮我看一下,上面代码中的返回值strTree,怎样才能在.aspx中实现出来
      

  7.   

    我用的是vb.net   你试试
    Page_Load 里加
    response.write(strTree)
      

  8.   

    也不行啊,我本来是直接用response.write写的,后来才改成用变量存放