我用vs2005中自带的treeview控件做个像csdn中左侧的树状目录时,一开始显示正常,后来怎么无原无故什么都不显示了,页面是空白的,我什么也没设置,代码也没改,连错误信息都没有,这是怎么回是啊,这已经不是第一次了.
哪为兄弟姐妹也同样遇到此问题,大家共同探讨一下,望大家不吝赐教.代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{    SqlConnection Conn;
    SqlDataAdapter myCmd;
    DataSet ds;
    string cmdSelect;
    string connstr = System.Configuration.ConfigurationManager.AppSettings["constr"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        Conn = new SqlConnection(connstr);
        if (!IsPostBack)
        {
            this.pl1.Visible = true;
            this.pl2.Visible = true;
            //调用数据集和递归方法
            Conn.Open();
            CreateDataSet();
            Conn.Close();
            InitTree(tvMenu.Nodes, "0");
        }
    }
    private DataSet CreateDataSet()//生成数据集 
    {
        cmdSelect = "select * from rs_bmbb where ztbz="+0;
        myCmd = new SqlDataAdapter(cmdSelect, Conn);
        ds = new DataSet();
        myCmd.Fill(ds, "tree");
        return ds;
    }
    protected void InitTree(TreeNodeCollection Nds, string parentbmbh)//用递归方法动态生成节点
    {
        DataView dv = new DataView();
        TreeNode tmpNd;
        string intId;
        dv.Table = ds.Tables["tree"];
        dv.RowFilter = "parentbmbh='" + parentbmbh + "'";
        foreach (DataRowView drv in dv)
        {
            tmpNd = new TreeNode();
            tmpNd.Value = drv["bmbh"].ToString();
            tmpNd.Text = drv["bmmc"].ToString();
            tmpNd.NavigateUrl = "bjbmxx.aspx?id=" + tmpNd.Value;
            Nds.Add(tmpNd);
            intId = drv["parentbmbh"].ToString();
            InitTree(tmpNd.ChildNodes, tmpNd.Value);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Conn.ConnectionString = connstr;
        Conn.Open();
        SqlCommand comm = new SqlCommand("SELECT COUNT(*) AS Expr1 FROM OA_GSB WHERE (GSBS = 00) AND (pwd = '"+this.TextBox1.Text.Trim()+"')",Conn);
        int i=Convert.ToInt32(comm.ExecuteScalar());
        if (i > 0)
        {
            this.pl1.Visible = false;
            this.pl2.Visible = true;        }
        else
        {
            Response.Write("<script>alert('密码错误请重新输入!')</script>");        }
        Conn.Close();
    }
}
前台:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="left.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="pl1" runat="server" Width="200px">
        <table border="0" cellpadding="0" width="100%" class="tableframe" style="margin:0px 0px 0px 0px">

<tr class="listtitle">
<td width="100%" class="listcelltitle" style="height: 18px; background-color: #cbcba3">请输入系统配置密码:</td>
</tr>
<tr class="listrow1">
<td width="100%" class="listcellrow" style="height: 25px">
                <asp:TextBox ID="TextBox1" runat="server" Width="100px"></asp:TextBox>
                &nbsp;
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="登陆" /></td>
</tr>
<tr class="listtail">
<td width="100%"align="left" style="height: 20px" >
测试用</td>
</tr>

</table>
        </asp:Panel>
        <asp:Panel ID="pl2" runat="server">
        <asp:TreeView ID="tvMenu" runat="server" ImageSet="Faq" ShowLines="True" ExpandDepth="0" Target="middle">
            <ParentNodeStyle Font-Bold="False" />
            <HoverNodeStyle Font-Underline="True" ForeColor="Purple" />
            <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" />
            <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="DarkBlue" HorizontalPadding="5px"
                NodeSpacing="0px" VerticalPadding="0px" />
        </asp:TreeView>
        </asp:Panel>
        
    
    </div>
    </form>
</body>
</html>