I have a treeview that is populated from the db. When the image icon next to the node is clicked than the childnodes are expanded. If the text is clicked than the user is redirected to another page but the nodes don't expand.
How can I expand the nodes before redirection takes place?
I though maybe i can raise the TreeView.TreeNodePopulate Event on page_load but i am not sure how and i am not sure if that will work.
I have a treeview that is populated from the db. When the image icon next to the node is clicked than the childnodes are expanded. If the text is clicked than the user is redirected to another page but the nodes don't expand.
How can I expand the nodes before redirection takes place?
I though maybe i can raise the TreeView.TreeNodePopulate Event on page_load but i am not sure how and i am not sure if that will work.
Any ideas?
Thanks
I think we can use this way, to register a JavaScript to nodes.
Check this demo code, this code show you how to register JavaScript to nodes,
whisky
Participant
1162 Points
577 Posts
TreeView.TreeNodePopulate Event
Aug 04, 2009 10:36 PM|LINK
Hi,
I have a treeview that is populated from the db. When the image icon next to the node is clicked than the childnodes are expanded. If the text is clicked than the user is redirected to another page but the nodes don't expand.
How can I expand the nodes before redirection takes place?
I though maybe i can raise the TreeView.TreeNodePopulate Event on page_load but i am not sure how and i am not sure if that will work.
Any ideas?
Thanks
Hong-Gang Ch...
All-Star
74696 Points
6768 Posts
Re: TreeView.TreeNodePopulate Event
Aug 10, 2009 09:03 AM|LINK
I think we can use this way, to register a JavaScript to nodes.
Check this demo code, this code show you how to register JavaScript to nodes,
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { string script = @"function treeNode(mEvent, text) { var o; // Internet Explorer if (mEvent.srcElement) { o = mEvent.srcElement; } // Netscape and Firefox else if (mEvent.target) { o = mEvent.target; } if(o.tagName == 'A' || o.tagName == 'a') { document.getElementById('txtID').value = o.id; document.getElementById('txtValue').value = o.innerHTML; document.getElementById('hfValue').value = o.innerHTML; if(document.getElementById('hfValue').value== 'MSN' ) { alert( 'I am the particular node, and my value is : '+document.getElementById('hfValue').value); } else { alert('I am not the particular node!'); } } }"; ScriptManager.RegisterClientScriptBlock(myTreeView, typeof(TreeView), "treeNodeClick", script, true); myTreeView.Attributes.Add("onclick", "javascript:return treeNode(event, '')"); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Demo</title> </head> <body> <form id="form1" runat="server"> <div> <asp:HiddenField ID="hfValue" runat="server" /> <asp:TextBox ID="txtID" runat="server"></asp:TextBox><asp:TextBox ID="txtValue" runat="server"></asp:TextBox> <asp:TreeView ID="myTreeView" runat="server" HoverNodeStyle-BackColor="Green" HoverNodeStyle-ForeColor="White"> <Nodes> <asp:TreeNode Text="My Computer"> <asp:TreeNode Text="Favorites"> <asp:TreeNode Text="News"> <asp:TreeNode Text="MSN" NavigateUrl="http://www.msn.com" /> <asp:TreeNode Text="MSNBC News" NavigateUrl="http://www.msnbc.msn.com" /> </asp:TreeNode> <asp:TreeNode Text="Technology"> <asp:TreeNode Text="Microsoft" NavigateUrl="http://www.microsoft.com" /> <asp:TreeNode Text="ASP.NET" NavigateUrl="http://www.asp.net" /> <asp:TreeNode Text="GotDotNet" NavigateUrl="http://www.gotdotnet.com" /> <asp:TreeNode Text="MSDN" NavigateUrl="http://msdn.microsoft.com" /> </asp:TreeNode> <asp:TreeNode Text="Shopping"> <asp:TreeNode Text="MSN Shopping" NavigateUrl="http://shopping.msn.com" /> <asp:TreeNode Text="MSN Autos" NavigateUrl="http://autos.msn.com" /> </asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="City Links"> <asp:TreeNode Text="MapPoint" NavigateUrl="http://www.mappoint.com" /> <asp:TreeNode Text="MSN City Guides" NavigateUrl="http://local.msn.com" /> </asp:TreeNode> <asp:TreeNode Text="Music Links"> <asp:TreeNode Text="MSN Music" NavigateUrl="http://music.msn.com" /> </asp:TreeNode> </asp:TreeNode> </Nodes> </asp:TreeView> </div> </form> </body> </html>If you have any feedback about my replies,please contactmsdnmg@microsoft.com.
Microsoft One Code Framework