Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / November 2005

Tip: Looking for answers? Try searching our database.

ASP.NET 2.0 TreeView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jamie.gunn@gmail.com - 08 Sep 2005 21:40 GMT
ASP.NET 2.0 TreeView

I have bound to my tree using the XMLDataSource both using and not
using the XPath attribute.

I am having trouble getting the TreeNodeExpanded event to work
correctly.

I have an event handler that prints out a message upon firing and I get
the message as I expect.

However, the node that I have selected to expand does not expand, it
seems as if just a post-back happens.

I then tried the method Expand() and ExpandAll() within the handler and
the node still does not expand.

I then stuck a little if statement in there to test whether the page
thought the node expanded.

if(e.Node.Expanded == true)
   Response.Write(e.Node.Test + " has expanded");

The result is a "n has expanded" at the top of the display but the node
still will not expand.

Does anyone else have some experience with this?

Thanks,

Jamie
Brock Allen - 09 Sep 2005 13:22 GMT
Are you trying to use the exapdn on demand feature? Here's a short snippet
that does that:

<script runat="server">
void OnPopulate(object sender, TreeNodeEventArgs e)
{
  string path = Server.MapPath(e.Node.Value);
  foreach (string directory in Directory.GetDirectories(path))
  {
     string name = Path.GetFileName(directory);
     TreeNode n = new TreeNode(name, e.Node.Value + "/" + name);
     n.PopulateOnDemand = true;
     e.Node.ChildNodes.Add(n);
  }
}
</script>

<asp:TreeView ExpandDepth="0" runat="server"
        OnTreeNodePopulate="OnPopulate">
   <Nodes>
       <asp:TreeNode PopulateOnDemand="true"
               Text="Root" Value="~" />
   </Nodes>
</asp:TreeView>

-Brock
DevelopMentor
http://staff.develop.com/ballen

> ASP.NET 2.0 TreeView
>
[quoted text clipped - 26 lines]
>
> Jamie
Frank - 30 Nov 2005 07:41 GMT
I have very simlar problems as follow code:
   <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       <asp:TreeView ID="TreeView1" runat="server"
OnTreeNodePopulate="TreeView1_TreeNodePopulate" ExpandDepth="0">
           <Nodes>
               <asp:TreeNode PopulateOnDemand="True"
SelectAction="SelectExpand" Text="Root" Value="c:\project">
               </asp:TreeNode>
           </Nodes>
       </asp:TreeView>
   </div>

c# code behind:
   protected void Page_Load(object sender, EventArgs e)
   {
       //TextBox1.Text = Request.Browser.SupportsCallback.ToString();
       TextBox1.Text = DateTime.Now.ToString();
   }
   protected void TreeView1_TreeNodePopulate(object sender,
TreeNodeEventArgs e)
   {
       TreeNode node = e.Node;
       if (node != null)
       {
           if (node.ChildNodes.Count == 0)
               InitNode(node);
       }

   }
   private void InitNode(TreeNode node)
   {
       string path = node.Value;
       string[] dirs = Directory.GetDirectories(path);
       foreach (string dir in dirs)
       {
           TreeNode child = new TreeNode(Path.GetFileName(dir), dir);
           node.ChildNodes.Add(child);
           child.PopulateOnDemand = true;
           child.SelectAction = TreeNodeSelectAction.SelectExpand;
           //child.Expanded = Directory.GetDirectories(dir).Length == 0 ?
false : true;
       }
   }

I put a textbox to show DateTime.Now in this page, I found textbox change
when I click or expand a tree node. So, that means this page post back to
server. I think I have set every thing I need to set. I still can not see
client side populate.

> Are you trying to use the exapdn on demand feature? Here's a short snippet
> that does that:
[quoted text clipped - 55 lines]
> >
> > Jamie

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.