Bind linqdatasource to TreeView

5 posts, 0 answers
  1. Zeyad
    Zeyad avatar
    10 posts
    Member since:
    Mar 2011

    Posted 15 Mar 2011 Link to this post

    Hello,

    I'm new to ASP.NET programming, so please bare with me. 

    I have a linqdatasource that is returning a table such as:

    Show Season# Episode#
    foo 1 1
    foo 1 2
    foo 1 3
    foo 2 1
    foo  2 2
    bar 1 1
    bar 1 2

    I want to represent this table in a TreeView with expand/collapse nodes such as:

    foo
    Season 1
    Episode 1
    Episode 2
    Episode 3
    Season 2
    Episode 1
    Episode 2
    bar
    Season 1
    Episode 1
    Episode 2

    How do I accomplish this scenario? 

    Thanks,
    Zeyad
  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 17 Mar 2011 Link to this post

    Hi Zeyad,

    What you need is binding to hierarchical data, you could check this article here explaining how to do achieve it.

    Best wishes,
    Dimitar Terziev
    the Telerik team
  3. Zeyad
    Zeyad avatar
    10 posts
    Member since:
    Mar 2011

    Posted 17 Mar 2011 Link to this post

    Thanks for the reply. The article assumes a certain structure within the database. The sample table I mentioned below does not seem to fit this type of structure. Do I have to programmatically change my database table to match the hierarchical table that TreeView expects? If so, how do i do that? 
  4. Zeyad
    Zeyad avatar
    10 posts
    Member since:
    Mar 2011

    Posted 29 Mar 2011 Link to this post

    Any thoughts?
  5. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 31 Mar 2011 Link to this post

    Hi Zeyad,

    To our regret you won't be able to bind the RadTreeView directly to your existing database. 
    You should query first your "shows" and add them to the RadTreeView node collection.
    Then for each "show" node you should get the corresponding "seasons" and then again apply the same procedure for the "episodes".

    All the best,
    Dimitar Terziev
    the Telerik team
Back to Top