操作TreeView屏幕总是闪烁!!怎么办??????

silentspring1983 2006-04-25 09:38:38
在我的代码中,当页面加载时,TreeView并不全部加载,只有当用户点击某一个结点前的"+"时,该结点的子结点才从服务器发送过来,这样一来性能会好一些。
但是每次点击"+"时,页面都会闪烁,现在我还不能把TreeView的AutoPostBack设置为false,要是那么做就不能动态加载子结点了。
请问有什么办法能解决闪烁问题吗?谢谢!
...全文
358 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ngv_yy 2006-04-29
  • 打赏
  • 举报
回复
把AUTOPOSTBACK设成FLASE就行了
liujiayu10 2006-04-26
  • 打赏
  • 举报
回复
CSDN是用的梅花雪的树,你可以到网上下载这个ASP版的树,然后改成ASPX的
silentspring1983 2006-04-25
  • 打赏
  • 举报
回复
我看CSDN是按照框架做的,我也想把页面分为两个iframe,左边的iframe显示TreeView,右边的iframe显示查询结果,用户点击左边的TreeView结点就可在右边得到查询结果。
怎样才能实现这样的功能呢?
lmbosos 2006-04-25
  • 打赏
  • 举报
回复
如果你用的是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>
zhouheng123456 2006-04-25
  • 打赏
  • 举报
回复
CSDN是直接用javascript来操作页面元素(DOM)当然不会闪...

silentspring1983 2006-04-25
  • 打赏
  • 举报
回复
真不知道CSDN是怎么解决这个问题的。。。。。。
january03 2006-04-25
  • 打赏
  • 举报
回复
是会闪烁的,没办法,据说用AJAX能解决部分问题,但是我还没有解决,郁闷中

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧