ASP.NET 2.0 TreeView Binding Issue



I'm trying to bind to the ASP.NET TreeView control and utilize the
PopulateOnDemand functionality. However, I am receiving the following
(very confusing) error: "PopulateOnDemand only supported when binding
the TreeView to a data source control using the DataSourceID property
or when the TreeNodePopulate event is handled."

Here is the code within my page load handler:

if (!IsPostBack)
TreeView1.DataSource = ExamList.GetExamList();

ExamList.GetExamList() returns a strongly typed list (ExamList) of
items of type ExamInfo, and implements the IHierarchicalEnumerable

Here is the code within the IHierarchicalEnumerable.GetHierarchyData:

public IHierarchyData GetHierarchyData(object enumeratedItem)
return (IHierarchyData)enumeratedItem;

ExamInfo implements IHierarchyData.

Here are the important IHierarchyData member implementations:

public IHierarchicalEnumerable GetChildren()
return null;

public IHierarchyData GetParent()
return null;

public bool HasChildren
get { return false; }

public object Item
get { return this; }

On the TreeView, I am handling the TreeNodeDataBound and
TreeNodePopulate and events. They are both wired up correctly as

Here is the code within my TreeNodeDataBound handler:

if (e.Node.Parent == null)
e.Node.SelectAction = TreeNodeSelectAction.SelectExpand;
e.Node.PopulateOnDemand = true;
e.Node.Value = ((IExam)e.Node.DataItem).ID.ToString();

Here is the code within my TreeNodePopulate handler:

int examID = Convert.ToInt32(e.Node.ValuePath);
Exam exam = Exam.GetExam(examID);
foreach (ExamPart part in exam.Parts)
TreeNode partNode = new TreeNode(part.Name);
foreach (PartItem item in part.Items)
TreeNode itemNode = new TreeNode(item.Name);

The misleading part of the error message is where it states "or when
the TreeNodePopulate event is handled". The event is properly wired
up, yet, the page load handler is throwing this exception immediately
after the TreeView1.DataBind(); statement is executed. In other
words, the TreeNodeDataBound event handler executes once for each
databound item, and after the last item is bound, it throws the

Any thoughts, ideas, or suggestions would be greatly appreciated!





Did you ever figure this one out? I'm having the exact same problem..



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