I wrote one according to the example and found that it will not be dynamically added. Let's take a look at Microsoft's instructions.
Http://msdn2.microsoft.com/zh-cn/library/system.web.ui.webcontrols.treenode.populateondemand (vs.80). aspx
Treenode. populateondemand = true
But the first node needs to be manually added, and then set populateondemand = true
Protected void treeviewinclutreenodepopulate (Object sender, treenodeeventargs E)
{
If (E. node. childnodes. Count = 0)
{
If (E. node. Depth = 0)
{
Fillbom (E. node );
}
Else
{
Fillbomdetail (E. node );
}
}
}
Void fillbom (treenode node)
{
String id = node. value;
Bomtableadapters. bommodeltableadapter oadapter = new bomtableadapters. bommodeltableadapter ();
Bom. bommodeldatatable obomtable = oadapter. getdata ();
If (obomtable. Rows. Count> 0)
{
Foreach (datarow row in obomtable. Rows)
{
Treenode newnode = new treenode (row ["model"]. tostring (), row ["model"]. tostring ());
Newnode. populateondemand = true;
Newnode. selectaction = treenodeselectaction. None;
Node. childnodes. Add (newnode );
}
}
}
Void fillbomdetail (treenode node)
{
String id = node. value;
Bomtableadapters. bommodelitemtableadapter oadapter = new bomtableadapters. bommodelitemtableadapter ();
Bom. bommodelitemdatatable obomtable = oadapter. getdatabymodel (ID );
If (obomtable. Rows. Count> 0)
{
Foreach (datarow row in obomtable. Rows)
{
Treenode newnode = new treenode (row ["code"]. tostring (), row ["code"]. tostring ());
Newnode. populateondemand = true;
Newnode. selectaction = treenodeselectaction. None;
Node. childnodes. Add (newnode );
}
}