Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 3rd, 2011, 02:57 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile N Level elements in single table

Hello Everyone,

I want to know that how we can design a table so that it contains the Parent and Child elements in itself? There should not be two separate tables for each element connected through foreign key constraint.

For example we may consider Category section in any web application. Where Categories, SubCategories, SubSubCategories, upto as many level as you want should be in single table.
Kindly tell me how to design such table and how to code to enter elements in such table in web forms?

Many thanks...
 
Old December 5th, 2011, 06:00 AM
Authorized User
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

only two columns required and neither u need to create primary foreign key relation nor size of db would increase as happens in case of denormalization.

cat subcat
----- ------
cat1 cat2
cat1--------cat3
cat1 ` cat4
cat2 ` cat5
cat2 ` cat6
cat3 ` cat7
cat3'''''''''''`, cat8
cat4 `,cat9
cat4 ...-` cat10
cat9 ``````cat11
 
Old December 5th, 2011, 06:02 AM
Authorized User
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

only two columns required and neither u need to create primary foreign key relation nor size of db would increase as happens in case of denormalization.

cat subcat
----- ------
cat1 cat2
cat1 cat3
cat1 cat4
cat2 cat5
cat2 cat6
cat3 cat7
cat3 cat8
cat4 cat9
cat4 cat10
cat9 cat11

cat1 has cat4-cat4 has cat 9-cat9 has cat 11

just remember to have all these names as unique or u will need a seperate table to keep id of every category

Last edited by sam0sunny; December 5th, 2011 at 06:05 AM..
 
Old December 6th, 2011, 01:34 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Default

Thanks Sam for reply. Is't possible to use structure like Cat SubCat CatId
I mean to say use Id of Category.
 
Old December 10th, 2011, 01:31 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Ok Now I have structure like this
Id (PK),
Name,
ParentId

How I can represent this data in hierarchy form like
Code:
Cat1
  SubCat1
  SubCat2
      SubSubCat1
      SubSubCat2
  SubCat3
Cat2
in dropdown list and repeater through EF?

Thanks.
 
Old December 14th, 2011, 02:45 AM
Authorized User
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sry 4 replying late.
u may use a tree view
set parentid of topmost categories to 0.
insert nodes with text of these categories names,then find those subcategories which come under these categories and add then to there corresponding parent nodes.
id name parentid
1 electronics 0
2 jewelry 0
3 pc 1
4 kitchen 1
5 ups 3
6 monitor 3
7 juicer 4
8 otg 4
 
Old December 14th, 2011, 10:12 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hi Sam,
No need to be sorry. Well in the meanwhile I had applied the some procedure that you mentioned. I kept ParentId = 0 for parent category. The only thing I need is to collect the parent child list and display them into Dropdownlist and repeater. I do not wanna use TreeView, as it will not solve the situation what a repeater can.

Thanks...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving a single value from a single column in a single row? Ron Howerton LINQ 2 May 17th, 2011 08:46 AM
<a> element in within block-level elements? steddie1 BOOK: Beginning Web Programming with HTML, XHTML, and CSS, 2nd Edition ISBN: 978-0-470-25931-3 2 March 3rd, 2009 04:43 AM
Get a Single Data Value from a Table pencilneck Visual Studio 2005 1 January 8th, 2008 02:55 PM
difference between row n table level triggers Hafiz Muhammad Mushtaq Oracle 1 July 9th, 2007 12:48 AM
How to get data from top level elements hubba09 XSLT 1 July 6th, 2007 07:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.