ASP.NET 2.0 TreeView

J

jamie.gunn

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
 
B

Brock Allen

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>
 
F

Frank

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top