It seems to work fine with his data sample but when i use it with my actual data it generate StackOverflowException was unhandled.

Below is the screen shot of the error.

Error is generated when it goes into sort of infinate loop where PID=6 My actual data which is show above has 23 records & is result of UNION from different tabel that is the reason i have multiple rows in table where PID=6 i am afraid it will also do same where pid=12.

@Mayur, Looks like a good solution but i am not able to understand it as it using LINQ and DataClasses1DataContext . I need it for asp.net-webform using c#
– LearningJan 3 '13 at 11:30

remove Dataclass1datacontext and context and instead of context you can use myDataTable.Select("ParentID == 0") and instead of IQueryable<Menu> menus you can use var menus.
– mayur RathodJan 3 '13 at 11:38

@Mayur, Appreciate your help i have updated question but it doesn't work i am doing something wrong in the code.
– LearningJan 3 '13 at 11:55

Thanks for your solution which seems to be a working one but it is generating StackOverFlowException in my case after implementing your solution. I noticed that i goes into loop endlessly which i was debugging it for some reason, I have actually 23 rows in my table i thought it might loop 23 time but it loops more that that & generates error for where pid=6, I will update my question & screen shots of error for reference. ANyway i appreciate your solution & hope you can solve this misty for me
– LearningJan 6 '13 at 4:12

1

I've made an update.Give it a try and let me know whether it solves your problem!Please mark as answered if my post helped you
– Denys WesselsJan 6 '13 at 14:34

@Dani, Thanks it works now with the duplicate PID also as required. Appreciate you help. I am sure this code will help lot of people as i could not find similar code which works with datatable. Great Solution.
– LearningJan 7 '13 at 6:46