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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.