• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

Treeview PopulateOnDemand fails

Hi

Can someone tell me why I cannot get this to work. The populate on demand function does not trigger

Here is the aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows">
            <ParentNodeStyle Font-Bold="False" />
            <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
                VerticalPadding="0px" />
            <Nodes>
                <asp:TreeNode Text="Available devices" Value="0" PopulateOnDemand="True"></asp:TreeNode>
            </Nodes>
            <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
                NodeSpacing="0px" VerticalPadding="0px" />
        </asp:TreeView>
   
    </div>
    </form>
</body>
</html>

Here is the Code behind.

Partial Class _Default
    Inherits System.Web.UI.Page
   
    Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
        Select Case e.Node.Depth
            Case 0
                Response.Write(e.Node)
                Exit Sub
            Case 1
                Response.Write(e.Node)
                Exit Sub
        End Select
    End Sub

any help would be appreciated. Thanks
0
nsfranklin
Asked:
nsfranklin
  • 2
1 Solution
 
TSmoothCommented:
Based on your code above, you're not attaching your event handler to the event. You need to add a "Handles TreeView1.TreeNodePopulate" to the end of your event handler definition:

Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
0
 
nsfranklinAuthor Commented:
Hi

Thanks for that, new code is
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" action="Default.aspx" runat="server">
   
    <div>
                <asp:TreeView ID="TreeView1" SkinId="Simple" Width="250" ExpandDepth="0" runat="server" AutoGenerateDataBindings="False">
          <Nodes>
            <asp:TreeNode Text="Inventory" SelectAction="SelectExpand" PopulateOnDemand="True" Value="Inventory"/>
            </asp:TreeNode>
          </Nodes>
        </asp:TreeView>

   
    </div>
    </form>
</body>
</html>

Code behind is

    Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
        Select Case e.Node.Depth
            Case 0
                Response.Write(e.Node.ToString)
                Exit Sub
            Case 1
                Response.Write(e.Node.ToString)
                Exit Sub
        End Select
    End Sub

Why can I only click on the node once to trigger the treenodepopulate, the page re-displays with the + missing and subsequent clicks to not show a response.
0
 
nsfranklinAuthor Commented:
Hi

Further to the above, my error, problem solved and points awarded for guidance.

Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now