Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Tree View

Status
Not open for further replies.

NeilV

Programmer
Oct 14, 2002
117
GB
Hello,

I'm trying to create a tree that will allow the user to select nodes items by way of check boxes. I was hoping to
maybe use the datagrid, but i don't have to if there is another way. Any ideas on how this can be done?

Neil

[bluegreedy]
 
Neil: Seems the TreeView Control would be a good approach. Here's some example code from a reference I have; perhaps it can help.

SimpleTreeView.aspx

<%@Import Namespace = &quot;System.Web.UI.HtmlControls&quot;%>
<%@ Register TagPrefix=&quot;IE&quot; Namespace=&quot;Web.UI.WebControls&quot;%>
Assembly=&quot;Microsoft.Web.UI.WebControls&quot; %>
<html>
<head><title>...</title></head>
<body>
<form runat=&quot;server&quot;>
<IE:TreeView
Runat=&quot;server&quot;>

<TreeNode 'imports MS.Web.UI.WebControls Namespace
Runat=&quot;server&quot;>
<TreeNode
Text=&quot;Invertebrates&quot;>
<TreeNode
Text=&quot;Vertebrates&quot;>
<TreeNode
Text=&quot;Plants&quot;>
<TreeNode
Text=&quot;Algae&quot;>
</TreeNode>

</ID:TreeView>
</form>
</body>
</html>

TreeView is not part of the core ASP.NET Framework, so the namespace must be explicitly imported to refer to classes in the IE WebControls assembly.

IE Tag prefix is registered for the IE WebControls. Registering the prefix maps the prefix to the proper namespace for the controls.

If you want to detect when users select a particular node, you need to capture the SelectedIndexChanged event. Here's some more example code which demonstrates a subroutine associated with this event.

TreeViewSelectedIndexChanged.aspx

<%@....%> etc

<Script runat=&quot;server&quot;>
Sub TreeView_SelectedIndexChanged (s As Object, e As TreeViewSelectEventArgs)
lblSelectedNode.Text = treeBooks.GetNodeFromIndex(e.NewNode).Text
End Sub
</script>

<html>
.....
<form runat=&quot;server&quot;>
<IE:TreeView
id=&quot;treeBooks&quot;
AutoPostBack=&quot;true&quot;
OnSelectedIndexChanged=&quot;TreeView_SelectedIndexChanged&quot;
Runat=&quot;server&quot;>

<TreeNode
Text=&quot;ASP.NET Books&quot;>

<TreeView
Text=&quot;ASP.NET Unleased&quot; />

<TreeView
Text=&quot;ASP Tips, Code&quot; />

</TreeNode>
</IE:TreeView>
<p>
<asp:Label id=&quot;lblSelectNode&quot;
Runat=&quot;server&quot; />

</form>
...
</html>

...from S. Walther (good reference)




 
Thanks for your help! However, I am getting a parser error, which i can't figure out...

the error is:
&quot;File or assembly name Microsoft.Web.UI.WebControls, or one of its dependencies, was not found.&quot;

And it refers to:

&quot;<%@Import Namespace = &quot;System.Web.UI.HtmlControls&quot;%>
<%@Register TagPrefix=&quot;IE&quot; Namespace=&quot;Web.UI.WebControls&quot; Assembly=&quot;Microsoft.Web.UI.WebControls&quot;%>&quot;

Any suggstions as to what this could be?

Neil


 
its ok I have it sorted now....needed to install the Webcontrols first!

neil
 
I'm pretty new to ASP.net, so could you explain how you installed the Webcontrols?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top