This is my ASP code. I just took it from a sample:
This is my Page_Load code:
accessGroupNode.DataKey = accessGroup.AccessGroupKey.ToString();
When I step through the code, I clearly see that 1 node is being added to the collection AccessTreeView.Nodes. However, when the tree view is displayed, it is completely empty.
This is my DemandLoad code, however it is not being hit so I think it is irrelevent:
childAccessGroupNode.DataKey = childAccessGroup.AccessGroupKey.ToString();
I think the problem here is calling AccessTreeView.DataBind() immediately after adding the node. The treeview supports bound and unbound modes - adding nodes directly to the controls collection is unbound mode, while calling DataBind() is bound mode and expects setting DataSource or DataSourceID properties. Calling DataBind() with empty DataSource/DataSourceID essentially clears the nodes.
I think if you are adding nodes directly to the nodes collection, you do not need to call DataBind() so removing the line should hopefully address the problem.
Rumen Stankov (MCSD.NET)
Thanks. I tried commenting that line out but it makes not difference.
Could this be something to do with images or something? I'm only using text at the moment. The version of the UltraWebNavigator is 7.3.20073.38 could that have something to do with it?
From what I see, I really do not see where the poblem originates. Maybe it is something in project or page setup, or the PopupContainer that I see you are using inteferes in some way.
I believe in these cases, where problems are tough to find, the best approach is to assemble a small subset of your project reproducing the problem and send it to our dedicated Developer Support department via this link:
Some info on environment (browser, VS.NET / .NET version, etc) will also help them repro the problem and advice further.
I made test app with the same code and it works fine. The problem seems to be something specific to the popup control. I'll investigate further. The popup control is a standard AjaxControlToolkit modal popup extender.
For now I am just using the tree view on a normal page but I will have to move it to a popup later.
I've got another problem now. When the page is loaded for the first time, the first node displays correctly. I expand the node and it correctly loads two chidren. However, when I expand one of those nodes, it clears out the tree altogeher. Here is all my code:
AccessTreeView.Nodes.Add( NewNode(accessGroup.Name, accessGroup.AccessGroupKey));
accessGroupNode.Text = name;
accessGroupNode.DataKey = key;
Here's a very simple app which has the same problem:
Also, IE makes that stupid clicking noise when I click on a node. That means that the page is refreshing. How do I stop that?
OK. The problems that I have stated here have been solved. I must have picked up the wrong ASP code somewhere. This ASP works:
But! Here's a new problem. This is my code:
ViewState[ViewState_Level] = 0;
childAccessGroupNode.DataKey = bla;
This correctly adds a node every time it is expanded. However in the DemandLoad event I find that e.Node is an empty node. And, e.Node.DataKey is null. It should be the number that I have set. Without a useful DataKey, I can't load anymore child nodes. I only get a useful e.Node the first time the nodes are expanded.
In this mode DataKey is not supported, but you can use DataPath . I think Vince has a great post on this here:
Actually I read another article and found that what I had to do was set the tree to manual and place the tree inside a WebAsyncRefreshPanel which I'm guessing is like an ASP UpdatePanel. Here is the code.
Funny that the samples don't show how this is done.
I can't really understand why you would use the other methods of populating the tree because in the two Ajax modes, only the DataPath property is persisted to the server side. With WebAsyncRefreshPanel, all the Nodes and their properties are persisted to the server side.
My advice is to use the WebAsyncRrefreshPanel and not the other modes that the samples use; unless, you only want to do processing on the client side. But, I can't really imagine a case where you would only want to work on the client side.