在我的代码中,当页面加载时,TreeView并不全部加载,只有当用户点击某一个结点前的"+"时,该结点的子结点才从服务器发送过来,这样一来性能会好一些。
但是每次点击"+"时,页面都会闪烁,现在我还不能把TreeView的AutoPostBack设置为false,要是那么做就不能动态加载子结点了。
请问有什么办法能解决闪烁问题吗?谢谢!
但是每次点击"+"时,页面都会闪烁,现在我还不能把TreeView的AutoPostBack设置为false,要是那么做就不能动态加载子结点了。
请问有什么办法能解决闪烁问题吗?谢谢!
解决方案 »
- 求可用的ASP.NET WEB页面打印方法,后台前台能用就行,别忘了引用集什么的都付上来昂
- IIS 部署问题
- 请问如何从DataTable里查询出指定的数据
- 有没有类似博客论坛这样的流程图啊
- 菜鸟 题问 事务 急用
- 用户控件有个属性是集合类型的,为什么在设计器上不显示呢?
- Response.cookies为什么是乱码?
- detailsview数据太长就不能更新??``急求救啊`!!!
- iframe如何获取parent中textbox的值?
- asp.net 怎么用 急!!!
- 如果datagrid中有多个选择事件,如何区分?还有怎样获取datagrid的列索引?
- 如何修改下载下来ASP.NET网站的源代码。
<%@ 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>
怎样才能实现这样的功能呢?