Displaying hierarchical data with the LinqDataSource

Monday, December 3, 2007

I ran into some frustration playing with the new LinqDataSource last night.  I was creating a FAQ page for a site and needed to show the Category followed by the list of questions/answers in that category.  This involved having a repeater nested within a parent repeater which was bound to a LinqDataSource.  The child repeater was then bound to the “Faqs” collection of the FaqCategory table.  The Linq to Sql designer is shown below as well as the repeater. 


After setting this up, I was not able to get the actual questions to display in the nested repeater.  I thought Linq would delay execution of the query to return the entire object graph.  I finally tried setting EnableUpdate attribute to “true” and was finally able to get the entire object graph. Hopefully this will save others some frustration.


  1. http:// says:

    Wooot… I was struggling with this very same issue on and off for the last couple of days. I just could not understand why it did not want to work. So for nested binding with a LinqDataSource you have to have EnableUpdate=true…. Thanks a million for this one Mike.


  2. christian says:

    heureka! ive been trying to find a clue about how to actually bind a datasource for the inner repeater. obviously its hard to find because its that simple… thx

  3. http:// says:

    This is not really hierachical data. This is NESTED data. I was actually looking for a way to get a LinqDataSource hooked up to a TreeView…

  4. http:// says:

    You can also put this in the datasource section:
    DataSource=”< %# container.dataitem.faqs %>”

    When doing this I didn’t have to enableupdate.

  5. Peter says:

    The problem is that you need to setup the relationship in your dbml. How would you do it without the relationship setup in code?

Leave a Reply