在我的代码中,当页面加载时,TreeView并不全部加载,只有当用户点击某一个结点前的"+"时,该结点的子结点才从服务器发送过来,这样一来性能会好一些。
    但是每次点击"+"时,页面都会闪烁,现在我还不能把TreeView的AutoPostBack设置为false,要是那么做就不能动态加载子结点了。
    请问有什么办法能解决闪烁问题吗?谢谢!

解决方案 »

  1.   

    是会闪烁的,没办法,据说用AJAX能解决部分问题,但是我还没有解决,郁闷中
      

  2.   

    真不知道CSDN是怎么解决这个问题的
      

  3.   

    CSDN是直接用javascript来操作页面元素(DOM)当然不会闪...
      

  4.   

    如果你用的是VS2005下的TreeView,那么是可以做到的。<%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %><script runat="server">  void PopulateNode(Object sender, TreeNodeEventArgs e)
      {    // Call the appropriate method to populate a node at a particular level.
        switch(e.Node.Depth)
        {
          case 0:
            // Populate the first-level nodes.
            PopulateCategories(e.Node);
            break;
          case 1:
            // Populate the second-level nodes.
            PopulateProducts(e.Node);
            break;
          default:
            // Do nothing.
            break;
        }
        
      }  void PopulateCategories(TreeNode node)
      {
        
        // Query for the product categories. These are the values
        // for the second-level nodes.
        DataSet ResultSet = RunQuery("Select CategoryID, CategoryName From Categories");    // Create the second-level nodes.
        if(ResultSet.Tables.Count > 0)
        {
        
          // Iterate through and create a new node for each row in the query results.
          // Notice that the query results are stored in the table of the DataSet.
          foreach (DataRow row in ResultSet.Tables[0].Rows)
          {
            
            // Create the new node. Notice that the CategoryId is stored in the Value property 
            // of the node. This will make querying for items in a specific category easier when
            // the third-level nodes are created. 
            TreeNode NewNode = new TreeNode(row["CategoryName"].ToString(), row["CategoryID"].ToString());
            
            // Set the PopulateOnDemand property to true so that the child nodes can be 
            // dynamically populated.
            NewNode.PopulateOnDemand = true;
            
            // Set additional properties for the node.
            NewNode.SelectAction = TreeNodeSelectAction.Expand;
            
            // Add the new node to the ChildNodes collection of the parent node.
            node.ChildNodes.Add(NewNode);
            
          }
          
        }
        
      }  void PopulateProducts(TreeNode node)
      {    // Query for the products of the current category. These are the values
        // for the third-level nodes.
        DataSet ResultSet = RunQuery("Select ProductName From Products Where CategoryID=" + node.Value);    // Create the third-level nodes.
        if(ResultSet.Tables.Count > 0)
        {
        
          // Iterate through and create a new node for each row in the query results.
          // Notice that the query results are stored in the table of the DataSet.
          foreach (DataRow row in ResultSet.Tables[0].Rows)
          {
          
            // Create the new node.
            TreeNode NewNode = new TreeNode(row["ProductName"].ToString());
            
            // Set the PopulateOnDemand property to false because these are leaf nodes and
            // do not need to be populated.
            NewNode.PopulateOnDemand = false;
            
            // Set additional properties for the node.
            NewNode.SelectAction = TreeNodeSelectAction.None;
            
            // Add the new node to the ChildNodes collection of the parent node.
            node.ChildNodes.Add(NewNode);
            
          }
          
        }  }  DataSet RunQuery(String QueryString)
      {    // Declare the connection string. This example uses Microsoft SQL Server and connects to the
        // Northwind sample database.
        String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI";     SqlConnection DBConnection = new SqlConnection(ConnectionString);
        SqlDataAdapter DBAdapter;
        DataSet ResultsDataSet = new DataSet();    try
        {      // Run the query and create a DataSet.
          DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
          DBAdapter.Fill(ResultsDataSet);      // Close the database connection.
          DBConnection.Close();    }
        catch(Exception ex)
        {      // Close the database connection if it is still open.
          if(DBConnection.State == ConnectionState.Open)
          {
            DBConnection.Close();
          }
          
          Message.Text = "Unable to connect to the database.";    }    return ResultsDataSet;  }</script><html>
      <body>
        <form runat="server">
        
          <h3>TreeView TreeNodePopulate Example</h3>
        
          <asp:TreeView id="LinksTreeView"
            Font-Name= "Arial"
            ForeColor="Blue"
            EnableClientScript="false" 
            OnTreeNodePopulate="PopulateNode"
            runat="server">
             
            <Nodes>
            
              <asp:TreeNode Text="Inventory" 
                SelectAction="Expand"  
                PopulateOnDemand="true"/>
            
            </Nodes>
            
          </asp:TreeView>
          
          <br><br>
          
          <asp:Label id="Message" runat="server"/>    </form>
      </body>
    </html>
      

  5.   

    我看CSDN是按照框架做的,我也想把页面分为两个iframe,左边的iframe显示TreeView,右边的iframe显示查询结果,用户点击左边的TreeView结点就可在右边得到查询结果。
        怎样才能实现这样的功能呢?
      

  6.   

    CSDN是用的梅花雪的树,你可以到网上下载这个ASP版的树,然后改成ASPX的