Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulateOnDemand does not work on data bound ASP.Net TreeView
    primarykey
    data
    text
    <p>I have a TreeView that is bound to a XmlDataSource control. I've added some TreeNodeBinding elements to define how I want the XML data to be shown.</p> <p>I have also added PopulateOnDemand=true to these TreeNodeBindings. However, doing so didn't change a thing and the entire XML tree is displayed. Moreover, the TreeNodePopulate event is not fired on node expand as well.</p> <p>Important information: I'm using ASP.NET 4.</p> <p>This is an example that reproduces the problem (very straight forward):</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" %&gt; &lt;script type="text/C#" runat="server"&gt; protected void TreeView1_TreeNodePopulate(Object sender, TreeNodeEventArgs e) { // This method is never called... } &lt;/script&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1" OnTreeNodePopulate="TreeView1_TreeNodePopulate" ExpandDepth="0"&gt; &lt;DataBindings&gt; &lt;asp:TreeNodeBinding DataMember="#" TextField="#" ValueField="#" PopulateOnDemand="true" /&gt; &lt;/DataBindings&gt; &lt;/asp:TreeView&gt; &lt;asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="Sample.xml" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The Sample.xml can be any xml file you want, it doesn't really matter.</p> <p>I tried to put a breakpoint within the <code>TreeView1_TreeNodePopulate</code> method and it was never hit.</p> <p>I also tried to:</p> <ul> <li>Set a TreeNodeBinding for each possible data member with PopulateOnDemand="true".</li> <li>Via code, go through all tree nodes and set their PopulateOnDemand property to <code>true</code>.</li> </ul> <p>Nothing worked.</p> <p>The only way the populate-on-demand thing worked was when I added nodes manually to the nodes instead of binding it to a data source.</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload