• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 75
  • Last Modified:

Populate <asp:TreeView, multilevel (8)


Hieracrhical Table dt
Columns -> int ContactID, int ParentID, string Name
row -> 1,  0, "USA"
row -> 2,  1,  "WA"
row->  3,  2,  "Seattle"
row->  4,  0,  "Canada"


I just need the code behind, my webpage works fine, I have successfully (after >50 hrs) populated parent and one level below, but everything keeps getting harder as I go deeper, searched much of those hours, I think some of the recursive methods may be what I need, but are beyond my skill set to design and build, I do understand them after someone else has created it.  I think many have done this before.

Kind Regards
  • 2
1 Solution
Bob LearnedCommented:
If you have a hierarchical data source, it is pretty simple to bind the TreeView.


ASP.net(C#) Custom Hierarchical Datasource

<asp:TreeView ID="tree" runat="server" DataSourceID="source" ExpandDepth="0">
<asp:HierarchicalObjectDataSource ID="source" runat="server" SelectMethod="GetData"
	TypeName="CSTruter.com.Data" DataParentField="ParentID" DataValueField="Value"
	DataTextField="Text" />

Open in new window

omgangIT ManagerCommented:
I just recently went through a similar exercise to bind a treeview to a entity objects from Dynamics CRM.  I used recursion as you mentioned.  I'd post my code but, to give credit where it is due, I found (and used) this post https://social.msdn.microsoft.com/Forums/windows/en-us/703f3f3f-f198-4b1d-8150-acd368a90cb7/treeview-from-datatable regarding binding a datatable to a treeview and it worked quite well for me.

OM Gang
SamCashAuthor Commented:
Thanks much, I was able to modify slightly for my application, (I did a simple example for my question) and everything works great!

Thanks for the help!

SamCashAuthor Commented:

Thanks for the assistance.  I would like to use this but I may be too green to understand.  I went through your site.  In my C# Table dt, do I just rename my columns to "ParentID", "Value", and "Text", change "CSTruter.com.Data" to my Table name "dt" or do I have to crunch all the data with the examples on your site, to use the 5 line snippet provided?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now