Dynamically populating and expanding TreeView from button click...

J

John Roper

Hi,

I have a tree control using Microsoft.Web.UI.WebControls.TreeView. We use
this to display a file/folder hierarchy. We only populate the top level on
page load, but we do add a single node for every folder with the text
"Working...". When a folder is opened, the Working... is displayed and then
we populate the nodes in the expand handler and everything works.

I have now added a button to populate and expand to a sub-file/folder. I
need to clear out the "Working" text and then populate with the real data. I
use ...Nodes.Clear() to do this, before adding in the new nodes. All my code
appears to work, but after my button click handler has completed I get a
NullReferenceException from System.UI.Control.OnBubbleEvent(Object source,
EventArgs args) [from RaiseBubbleEvent, OnCommand, RaisePostBackEvent,
ProcessRequestMenu).

If I remove the Nodes.Clear() everything works (although the Working...
nodes are left of course). Can anyone explain what's going on and what I
should do to avoid this exception please?

Thanks in advance

John Roper
 
H

Harolds

One of the reasons that the control is not supported I assume.
Try:
Treeviewname.Nodes.RemoveAt(0)
instead of clear
 
J

John Roper

Thanks for taking the time to reply.... I had already tried that. In fact I
tried commenting out all my code and it still happened. So I rebooted and now
everything works fine. Has anyone come across this sort of behaviour?
 
H

Harolds

Yes, I have had strange things start happening, which went away after a
reboot, many times.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top