Hello all
I am having a problem with dynamically loading treenodes with treeview control inside an accordion control. I am gettting "object Reference not set" when adding a treenode to the treeview using the following code:
treeview.Nodes.Add(treenode)
If I pull the treeview out of the accordion control the same code works as expected.
Here is the code inside aspx:
<AjaxControlToolkit:Accordion
ID="accNavigation"runat="server"
Width="250px"FramesPerSecond="40"
TransitionDuration="250"AutoSize="Fill"
SelectedIndex="0"CssClass=""
HeaderCssClass="accordionHeader"HeaderSelectedCssClass="accordionHeaderSelected"
ContentCssClass="accordionContent">
<Panes>
<AjaxControlToolkit:AccordionPaneID="apMyEvaluations"
runat="server">
<Header>
<ahref=""onclick="return false;">My Evaluations</a>
</Header>
<Content>
<asp:TreeViewID="tvMyEvaluations"
runat="server"NodeIndent="18"
NodeStyle-HorizontalPadding="5"SelectedNodeStyle-BackColor="navy"
SelectedNodeStyle-ForeColor="white"ShowLines="true">
</asp:TreeView>
</Content>
</AjaxControlToolkit:AccordionPane>
<AjaxControlToolkit:AccordionPaneID="AccordionPane2"
runat="server">
<Header>
<ahref=""onclick="return false;">Manager Listing</a>
</Header>
<Content>
<asp:TreeViewID="tvManagerListing"
runat="server"NodeIndent="0"
NodeStyle-HorizontalPadding="5"SelectedNodeStyle-BackColor="navy"
SelectedNodeStyle-ForeColor="white"ShowLines="true">
<Nodes>
<asp:TreeNodeText="Manager Listing"Value="L">
<asp:TreeNodeText="ASP .Net"Value="ASP"ImageUrl="Images/24_Manager.ico"></asp:TreeNode>
<asp:TreeNodeText="Visual Basic"Value="VB"ImageUrl="Images/24_Manager.ico"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</Content>
</AjaxControlToolkit:AccordionPane>
</Panes></AjaxControlToolkit:Accordion>
Below is the code used to build the tree nodes:
'TreeNode Declarations
Dim tnMyEvaluationsRootAs TreeNodeDim tnPrimaryAs TreeNode
Dim tnSecondaryAs TreeNode'Using the tree view for My Evaluations, populate tree nodes
WithMe.tvMyEvaluations'Instaniate a new parent node
tnPrimary =New TreeNode("Primary","PRIMARY","~/Images/16_Copy.ico")'Add primary evaluation
tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 1","1","~/Images/16_User.ico"))tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 2","2","~/Images/16_User.ico"))
tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 3","3","~/Images/16_User.ico"))tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 4","4","~/Images/16_User.ico"))
tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 5","5","~/Images/16_User.ico"))tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 6","6","~/Images/16_User.ico"))
tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 7","7","~/Images/16_User.ico"))tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 8","8","~/Images/16_User.ico"))
tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 9","9","~/Images/16_User.ico"))tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 10","10","~/Images/16_User.ico"))
tnPrimary.ChildNodes.Add(New TreeNode("Employee, Some 11","11","~/Images/16_User.ico"))
'Instaniate a new parent node
tnMyEvaluationsRoot =New TreeNode("My Evaluations","MY_ROOT","~/Images/16_Copy.ico")'Add primary evaluations to root node
tnMyEvaluationsRoot.ChildNodes.Add(tnPrimary)
'Add node to My Evaluations tree view
.Nodes.Add(tnMyEvaluationsRoot)
EndWithAny help would be greatly appreciated.
Tom
Hi Tom,
I can't find the line "treeview.Nodes.Add(treenode)" in your code snippet.
According to your description, it seems treeview object is null. And such problem is usually caused by use FindControl to get reference to treeview object, you get null reference when the method fails. Please make sure the method is invoked on the right parent control.
If this doesn't help, please post relevant code.
Also, the treeview doesn't work well with most ajax things, including updatepanel (which could also be the source of your problem)..
A nice workaround is to use the treeview inside an iframe (just hide the frameborder and remove margins of the frame and noone will never know.. ;o) ).
No comments:
Post a Comment