Last post Aug 26, 2010 11:32 AM by atconway
Aug 26, 2010 07:21 AM|gridview|LINK
I have to create a aspx page where end users can create, edit and delete category and their subCategory from it.
Please suggest what is simple way to do above? using .Net
PS: a category can have zero or more subcategory and subcategory will not have any of its own subcategory, i.e. there are only two levels.
Aug 26, 2010 07:58 AMfirstname.lastname@example.org|LINK
create a table
Id CateName ParentId
1 Electronic 0
2 Freeze 1
3 Mobile 1
4 Jewellery 0
5 Ring 4
6 Ear Ring 4
the above table represent you both cate and sub cate
if parent id= 0 means Main Category
if parent id > 0 it means this is sub category of parent id.
and you can add/edit/detele the same record in single table.
Aug 26, 2010 11:32 AM|atconway|LINK
The last suggestion should work, but I would prefer to normalize the solution further to organize the data better
and to be more scalable in case more options arise, and there are several ways to do this.
One is to have a single table named Categories that has all names and IDs like below:
The the second table would be a lookup of the 1st table. If you are certain
there would only be 2 levels ever you can identify the ID type exlicitly with a bit field. If you think it ever could grow, you could further normalize and add a 3rd table that is called Category Type. 1st the table with the explicity definition
ID fkCategoryName IsParentCategory fkParentCategoryID
1 2 1 NULL
2 5 0 4
...or you could make a 3rd table that could contain 1..n Category types like below:
..and then change the above table to the following:
ID fkCategoryName fkCategoryType fkParentCategoryID
2 5 2 4
Then to implement this physically in the ASP.NET application you could use a control like a GridView to allow add/edit/delete capability of the different variations above. If your criteria changes and you can have 1...n subcategories at runtime, you might
want to look into a TreeView control where child items could be dynamically added.