Multilevel nested product categories display with asp.net and sql server?

Here's what you want. This stored procedure uses a "CTE" or "common table expression". I'm not a pro at them but they're very usefull.

Definatly recommend looking them up SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE GetRecursiveTest AS BEGIN ;WITh Tree (cat_id, cat_name, parent_cat_id, level, Sort) AS ( SELECT cat_id, cat_name, parent_cat_id, 0 AS level, CONVERT(varchar(255), cat_name) AS Sort FROM RecursiveTest WHERE parent_cat_id = 0 UNION ALL SELECT RT. Cat_id, RT. Cat_name, RT.

Parent_cat_id, Parent. Level + 1 AS level, CONVERT(varchar(255), Parent. Sort + ' -> ' + RT.

Cat_name) AS Sort FROM RecursiveTest RT INNER JOIN Tree as Parent ON Parent. Cat_id = RT. Parent_cat_id ) SELECT Sort FROM Tree ORDER BY Sort END GO Actually, if you change that last select to "selct * from tree" you'll get more data about the hierarchy Here's a link to a good resource for CTE's.

Here's what you want. This stored procedure uses a "CTE" or "common table expression". I'm not a pro at them but they're very usefull.

Definatly recommend looking them up. SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE GetRecursiveTest AS BEGIN ;WITh Tree (cat_id, cat_name, parent_cat_id, level, Sort) AS ( SELECT cat_id, cat_name, parent_cat_id, 0 AS level, CONVERT(varchar(255), cat_name) AS Sort FROM RecursiveTest WHERE parent_cat_id = 0 UNION ALL SELECT RT. Cat_id, RT.

Cat_name, RT. Parent_cat_id, Parent. Level + 1 AS level, CONVERT(varchar(255), Parent.

Sort + ' -> ' + RT. Cat_name) AS Sort FROM RecursiveTest RT INNER JOIN Tree as Parent ON Parent. Cat_id = RT.

Parent_cat_id ) SELECT Sort FROM Tree ORDER BY Sort END GO Actually, if you change that last select to "selct * from tree" you'll get more data about the hierarchy. Here's a link to a good resource for CTE's.

Awesome! Knew about CTE's but had no idea how to implement them to solve this. Bravo my friend :-) – Kunal Jun 16 '10 at 10:39.

If you use LINQ i´d suggest adding a new property which just represents the category with all parentcategorys and use the recursion there, so it´s easy for you to access it in asp.net.

Thanks Patrick for your reply. Actually I really want to start using LINQ but have no idea from where and how to get started :-( – Kunal Jun 14 '10 at 13:47 I started with this tutorial: weblogs.asp. Net/scottgu/archive/2007/09/07/… starting at part 1.It´s a really good tutorial.

If you need some lookup on how to query something or use a specific feature of LINQ queries you can use: msdn.microsoft. Com/en-us/vcsharp/aa336746. Aspx – kamahl Jun 14 '10 at 15:15 To add properties as I said above look at this question: stackoverflow.

Com/questions/587836/linq-add-property-to-results hope this helps =) – kamahl Jun 14 '10 at 15:16 Thanks a tonne Patrick. Really cant thank you enough. Appreciate it :-) – Kunal Jun 14 '10 at 10:33.

Now when a user wants to add a product he should be able to select multiple categories from a listbox(multiselection enabaled). I know that to achieve this I need to use recursive programming. But how can we do it via stored procedures?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions