|
| |
| dbalasko | Asp.Net User |
| Treeview problem | 5/24/2007 9:21:16 AM |
0/0 | |
|
Here is the problem: I have an XML bound Treeview control which displays product categories and sub-categories. When a sub-category is clicked, a new page is opened displaying products. Now I want this subcategory to stay expanded. First I had to remove NavigateUrlField from the TreeNodeBinding since OnSelectedNodeChanged is not beeing fired in that case. I solved the problem by storing the URL in the ValueField property.
Anyway, here is the Treeview definition: <asp:TreeView ID="TreeView2" runat="server" DataSourceID="XmlDataSource1" ImageSet="Custom" NodeIndent="10" ExpandDepth=1 OnSelectedNodeChanged=store_node> Here is the Sub being fired: Sub store_node(ByVal sender As Object, ByVal e As System.EventArgs) Session("node") = TreeView2.SelectedNode.ValuePath ' store the ValuePath in Session If Len(TreeView2.SelectedValue.ToString) > 5 Then Response.Redirect(TreeView2.SelectedValue) ' redirect to the product page if these is a link End Sub After that, Session("node") looks something like this: Kategorije/Informatika/procesori/katalog.aspx?grupa=110050&main=313&gn=PROCESORI&pgn=AMD%20AM2 Here is the code I use to select that node: If Not Session("node") Is Nothing Then If Session("node").ToString <> "" Then Dim selNode As TreeNode = TreeView2.FindNode(Session("node").ToString) selNode.Select() End If End If Session("node") = ""
But it's not wokring, I get the following error: "System.NullReferenceException: Object reference not set to an instance of an object" in the line selNode.Select() Any help would be appriciated. |
| grim93 | Asp.Net User |
| Re: Treeview problem | 5/25/2007 10:56:47 AM |
0/0 | |
|
Be Sure to check for object instance before trying to assign a value. i.e. If not isNothing(selNode) then selNode.Select() end if PS when do you call this method on page load or some other event. |
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/25/2007 11:49:55 AM |
0/0 | |
|
I tried it but nothing happens, there is no error now but the code between if...end if is not beeing executed at all.
If Not IsNothing(selNode) Then selNode.Select() Response.Write(selNode.Text) End If
The method is called on page load. |
| Amanda Wang - M | Asp.Net User |
| Re: Treeview problem | 5/28/2007 3:37:55 AM |
0/0 | |
|
Hi,
In your treeview you set ExpandDepth is 1, you could change the treeview ExpandDepth property, set its value is FullyExpand.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Yours sincerely, Amanda Wang Microsoft Online Community Support |
| Amanda Wang - M | Asp.Net User |
| Re: Treeview problem | 5/28/2007 8:49:43 AM |
0/0 | |
|
Hi,
If you want to make the node be selected, please do not use selNode.Select(), try to use selNode.Selected = true;
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Yours sincerely, Amanda Wang Microsoft Online Community Support |
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/28/2007 9:04:55 AM |
0/0 | |
|
Tried it, but nothing.
Dim selNode As TreeNode = TreeView2.FindNode(Session("node").ToString) 'I think the problem lies here, no node is found so the if...end if block after that is not executed at all If Not IsNothing(selNode) Then selNode.Selected = True Response.Write(selNode.Text) End If
|
| Amanda Wang - M | Asp.Net User |
| Re: Treeview problem | 5/28/2007 10:11:48 AM |
0/0 | |
|
Hi,
The value of the node's ValuePath is the path fron the root node to the current node, it should be like this "Home/Administration/Sub 1", I do not understand
why your Session("node")( Session("node") = TreeView2.SelectedNode.ValuePath ) like this:
Kategorije/Informatika/procesori/katalog.aspx?grupa=110050&main=313&gn=PROCESORI&pgn=AMD%20AM2
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Yours sincerely, Amanda Wang Microsoft Online Community Support |
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/28/2007 10:17:16 AM |
0/0 | |
|
I defined ValueField="URL", and obviously this value field is also passed to the ValuePath. I did this because this is the only way (that I know) to pass the URL value. If I use NavigateUrlField then OnSelectedNodeChanged is not fired. |
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/28/2007 10:20:48 AM |
0/0 | |
|
U just tried removing ValueField="URL" from the TreeNodeBinding, so the ValuePath looks like this now:
Kategorije/Informatika/procesori/amd am2 But it still doesn't work, so I guess the URL in ValuePath doesn't make a difference.
|
| Johnson2007 | Asp.Net User |
| Re: Treeview problem | 5/29/2007 4:00:08 AM |
0/0 | |
|
I am keeping tracking this question from the very begining. and I have been trying it following Amanda's sugguestion, and it all worked. Therefore, may I ask you what your fanal question is? if the following code didn't execute or there was no node be selected?
If Not IsNothing(selNode) Then selNode.Select() Response.Write(selNode.Text) End If
Johnson |
| Amanda Wang - M | Asp.Net User |
| Re: Treeview problem | 5/29/2007 4:32:33 AM |
0/0 | |
|
Hi,
I think we are on the wrong way to solve your original problem. the problem is that you want to the sub-category to open a subpage in a new page, and keep the sub-category staying expanded. Right?
If it is right, you could only set the ExpandDepth =FullyExpand, do not need to implement it by codebehind.
The findnode method's parameters valuepath that is the value path of a node(from the root node to current node), but your Session("node").ToString is not a path of the node, but is an url, when you use the findnode method to get the node ( TreeView2.FindNode(Session("node").ToString) ) from treeview control at the specified value path, it will show error.
If these could not help you, would you please provide the xml file for futher help!
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Yours sincerely, Amanda Wang Microsoft Online Community Support |
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/29/2007 7:06:11 AM |
0/0 | |
|
>Hi, > I think we are on the wrong way to solve your original problem. the problem is that you want to the sub-category to open a subpage in a new page, and keep the sub-category staying expanded. Right?
Yes, exactly
>If it is right, you could only set the ExpandDepth =FullyExpand, do not need to implement it by codebehind.
But then all the subcategories will be expanded all the time, and I don't wan't that, since there will be many of them
>The findnode method's parameters valuepath that is the value path of a node(from the root node to current node), but your Session("node").ToString is not a path of the node, but is an url, when you use >the findnode method to get the node ( TreeView2.FindNode(Session("node").ToString) ) from treeview control at the specified value path, it will show error.
I also tried it without the link, so the Session("node") would only contain the path but it still didn't work >If these could not help you, would you please provide the xml file for futher help! Here is my XML: <?xml version="1.0" ?>
<Kategorije>
<MenuItem1 Title="Auto akustika"> <MenuItem3 Title="Dodatna oprema" URL="katalog.aspx?grupa=760090&main=1&gn=Auto%20akustika&pgn=Dodatna%20oprema"/> <MenuItem3 Title="Kablovi" URL="katalog.aspx?grupa=760070&main=1&gn=Auto%20akustika&pgn=Kablovi"/> </MenuItem1> <MenuItem1 Title="Informatika"> <MenuItem2 Title="ra?unala"> <MenuItem3 Title="pc racunala" URL="katalog.aspx?grupa=100010&main=315&gn=RACUNALA&pgn=PC%20ra?unala"/> </MenuItem2> <MenuItem2 Title="procesori"> <MenuItem3 Title="amd am2" URL="katalog.aspx?grupa=110050&main=313&gn=PROCESORI&pgn=AMD%20AM2"/> <MenuItem3 Title="intel celeron" URL="katalog.aspx?grupa=110010&main=313&gn=PROCESORI&pgn=Intel%20Celeron"/> </MenuItem2> </MenuItem1>
</Kategorije>
|
| Johnson2007 | Asp.Net User |
| Re: Treeview problem | 5/29/2007 7:32:24 AM |
0/0 | |
|
>>I also tried it without the link, so the Session("node") would only contain the path but it still didn't work.
Could you please discribe more clearly how it didn't work? what do you want it to do? and could you please tell me whether you still bind the Valud filed to "URL"? Is it the code between If...end not executed? if so did you debug it what the Session("node")'s value was? Thank you!
Johnson |
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/29/2007 7:46:10 AM |
0/0 | |
|
at the moment I am not binding the Value field to URL, the code between if..end if is still not executed, since no node is still beeing found. the value of Session("node") is for ex. "Kategorije/Informatika/procesori/intel celeron" here is the latest version of the TreeView (all the code bellow is placed in a file "menu.ascx" which is called from all the pages): <asp:TreeView ID="TreeView2" runat="server" DataSourceID="XmlDataSource1" ImageSet="Custom" NodeIndent="10" ExpandDepth=1 OnSelectedNodeChanged=sel_node> <LevelStyles> <asp:TreeNodeStyle ChildNodesPadding=2 cssclass="izdvojeni" Font-Underline="true" /> <asp:TreeNodeStyle NodeSpacing=4 cssclass="tab1" Font-Underline="true"/> <asp:TreeNodeStyle cssclass="tab2" Font-Underline="true" /> <asp:TreeNodeStyle cssclass="tab3" Font-UnderLine="True" /> </LevelStyles> <DataBindings> <asp:TreeNodeBinding DataMember="MenuItem1" TextField="Title" SelectAction="Expand" /> <asp:TreeNodeBinding DataMember="MenuItem2" TextField="Title" SelectAction="Expand" /> <asp:TreeNodeBinding DataMember="MenuItem3" TextField="Title" SelectAction="Select" /> </DataBindings> </asp:TreeView> Here is the sel_node sub: Sub sel_node(ByVal sender As Object, ByVal e As System.EventArgs) Session("node") = TreeView2.SelectedNode.ValuePath Response.Redirect("about.aspx") 'this is a test page which also contains menu.ascx where the selected node should be expanded End Sub And finally here is Page_Load of the menu.ascx: Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not Session("node") Is Nothing Then Response.Write(Session("node")) If Session("node").ToString <> "" Then Dim selNode As TreeNode = TreeView2.FindNode(Session("node")) If Not IsNothing(selNode) Then selNode.Selected = True Response.Write(selNode.Text) selNode.Expand() End If End If End If Session("node") = "" End Sub Could it maybe be that there is no node found because the treeview is still not populated at the moment?
|
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/29/2007 8:34:27 AM |
0/0 | |
|
I got it to work, partially at least. It seems the problem was that the treeview was not populate on pageload when I tried to find the node, so now I did the following: <asp:TreeView ID="TreeView2" runat="server" DataSourceID="XmlDataSource1" ImageSet="Custom" NodeIndent="10" ExpandDepth=1 OnSelectedNodeChanged=sel_node OnDataBound=treeview_bound> Removed all the code from page_load, and made a new sub:
Sub treeview_bound(ByVal sender As Object, ByVal e As System.EventArgs) If Not Session("node") Is Nothing Then If Session("node").ToString <> "" Then Dim selNode As TreeNode = TreeView2.FindNode(Server.HtmlDecode(Session("node"))) If Not IsNothing(selNode) Then selNode.Selected = True Try TreeView2.CollapseAll() Dim nodeToExpand As TreeNode = selNode While Not (nodeToExpand Is Nothing) nodeToExpand.Expanded = True nodeToExpand = nodeToExpand.Parent End While Catch ex As Exception End Try End If End If End If End Sub So this works now. But when I try using NavigateUrlField="URL", funny thing happens: the sel_node sub is not executed any more !? Any ideas why? Or is there maybe some other way I could use the URL from XML? |
| dbalasko | Asp.Net User |
| Re: Treeview problem | 5/29/2007 8:52:09 AM |
0/0 | |
|
Everything works now My bad in the last post, I got so confused with all this that I tried using NavigateUrlField="URL" instead of ValueField="URL". So now I added ValueField="URL", and everything works fine, a new page is opened with the link I passed, and the selected node is expanded. Thank you all for your feedback. |
|
| |
Free Download:
Books: Visual C# 2005 Recipes: A Problem-Solution Approach Authors: Allen Jones, Matthew MacDonald, Rakesh Rajan, Pages: 565, Published: 2006 Visual Basic 2005 Recipes: A Problem-Solution Approach Authors: Todd Herman, Allen Jones, Matthew MacDonald, Rakesh Rajan, Pages: 664, Published: 2007 Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers Authors: Tim Patrick, John Craig, John Clark Craig, Pages: 713, Published: 2006 Visual Basic 2008 Recipes: A Problem-Solution Approach Authors: Todd Herman, Allen Jones, Matthew MacDonald, Rakesh Rajan, Pages: 680, Published: 2008 .NET Programming 10-minute Solutions: 10-Minute Solutions Authors: A. Russell Jones, Mike Gunderloy, Pages: 433, Published: 2004 Pro ASP.NET 2.0 in VB 2005: From Professional to Expert Authors: Laurence Moroney, Matthew MacDonald, Pages: 1253, Published: 2006 Access 2003 VBA Programmer's Reference: programmer's reference Authors: Patricia Cardoza, Patricia DiGiacomo, Teresa Hennig, Graham Seach, Armen Stein, Pages: 984, Published: 2004 Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional Authors: Matthew MacDonald, Pages: 954, Published: 2007 Beginning ASP.NET 3.5 in VB 9.0: From Novice to Professional Authors: Matthew MacDonald, Pages: 1149, Published: 2007 Pro .NET 2.0 Windows Forms and Custom Controls in VB 2005 Authors: Matthew MacDonald, Pages: 1036, Published: 2006 Web:Tree view problem [Archive] - CodeGuru Forums Click to See Complete Forum and Search --> : Tree view problem ... Suppose I have one form having a tree view on it. ... ASP.NET Microsoft.Web.UI.WebControls Treeview Problem - ASP.NET Forums WebControls Treeview Problem. Last post 09-24-2008 8:57 PM by Moosdau. 2 replies . Sort Posts:. Oldest to newest, Newest to oldest ... TreeView problem Talk about TreeView problem. ... Old 11-27-2005, 12:30 PM. christof. Posts: n/a. Default Once again a TreeView problem ... :: View topic - TreeView problem Posted: Mon Aug 18, 2008 3:52 pm Post subject: TreeView problem ... I'am using TreeView for complex data where nodes are added dynamic in ... TreeView problem - .NET C# TreeView problem. Get answers to your questions in our .NET C# forum. Tree View Problem - VB.NET Tree View Problem - VB.NET Community and Forum - Our VB.NET forum is the place for Q&A-style discussions related to this language. pyGtk treeview problem - Ubuntu Forums pyGtk treeview problem Programming Talk. ... I'm trying to use a treeview to display info about some files, but the problem is, ... Treeview problem,9 - ng.asp-net-forum ... Treeview problem, > ROOT > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.internet_explorer_web_controls, Date: 8/29/2005 8:52:13 AM, ... C# .NET C# TreeView Problem C# TreeView Problem. Arvind Singh posted at 11-May-06 02:00. Hi!! Everybody I have a treeview which i am populating through database. ... Custom treeview problem - mozilla.dev.extensions | Google Groups Local: Tues, Sep 9 2008 11:05 pm. Subject: Custom treeview problem ... with a custom treeview. I followed the instructions found in the MDC, but ... Videos: Enable Hidden Administrator Account okay i didnt check, but incase its too blurry in the video to see, in the run box, type in "regedit.exe", and follow this path in registry ... GCCS97 #148 Proceedings of the GCC Developers Summit 2007 From http://ols.108.redhat.com/2007/GCC-Reprints/GCC2007-Proceedings.pdf . GIMPLE nodes in the GIMPLE tree view area, and highlights ... Creatoon - 4th test - keeping pivot points locked to a body It was easy to find out how to create a pivot point for any or all elements in an object (in this case, the grumpy old man). It took a little bit ... Structuring Personal Information When Everything Can Be Saved ... Google TechTalks
May 17, 2006
William Jones
William Jones is an Research Associate Professor in The Information School at the University of ... |
|
Search This Site:
|
|