How to bind data in asp.net c# treeview control

12,826

This may be useful :

TreeView control expects a heirarchical data structure like xml/sitemaps, so we cant bind the DataTable to it directly. Use data table Select where ParentID = ID

Please use a recursive method to create child items relevent to current menu item ID, refer to link below for code.

http://www.charith.gunasekara.web-sphere.co.uk/2010/10/how-to-bind-datatable-to-aspnet.html

n below link will help you creating ur own tree view control.

http://www.codeproject.com/KB/tree/DataBoundTreeView.aspx

Share:
12,826
Bob
Author by

Bob

Updated on June 04, 2022

Comments

  • Bob
    Bob almost 2 years

    I have never used treeview control in asp.net but now I need to bind data to it. My stored procedure from sql server is returning the the values as below. I m using c#

    TermID  ParentID  Name
    2021    0          A. Geographic locations
    3602    2021       Oceania
    3604    3602       Australasia
    3621    3604       New Zealand
    3619    3604       Pacific Islands
    3585    3619       Polynesia
    3592    3585       Samoa
    3594    3592       American Samoa
    

    Each Term has parentID and any TermID with ParentID=0 is the root node. How can we bind this data to treeview. I will appreciate any advise or examples