Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have category and subcategory tables,
In category tables consist of all categories and whereas in sub category table consist of all subcategory of each category.
These are entered in Master form.

I have web form in which I have to bind all categories in a check boxes,
when each category check box checked I need to bind its respective subcategories in another check box list. same way I have to bind all Subcategories in each category checked true.

While saving I have to save all subcategories and categories . But I have a problem that how I can identify this subcategory belongs to which category.
Posted
Updated 7-Dec-10 23:26pm
v4
Comments
TweakBird 7-Dec-10 4:18am    
Edited for readability.
[no name] 7-Dec-10 16:41pm    
Edited for readability? Really? :) Not very clear to me.
Hiren solanki 8-Dec-10 5:27am    
Edited for ultimate readability :) , I tried my best to correct grammar and preserving the same understanding as OP want.

First, you need to have some class to store your category collection in tree.

For example:
public class CategoryBO
{
 public int CategoryID{get;set;}
 public List<CategoryBO> SubCategories{get;set;}
}

or
public class CategoryBO
{
 public int CategoryID{get;set;}
 public int? ParentCategoryID{get;set;}
}


Then you should implement some method to bind checkboxlist or treeview (with checkboxes) into some control in which you will save required information about category (f.e. with ParentCategoryID to identify parent).
 
Share this answer
 
v4
Comments
Toniyo Jackson 9-Dec-10 6:54am    
Use code block for code.
karthikkushala 9-Dec-10 7:46am    
how i can save all subcategories at atime like supose i have a category (employee,unemployee)
i got two check boxes of(employee and Unemployee) which are cateogory. then when am clickin on first check box Employee i need to display Govt.employee,Prvt Employee,Self Employee Etc..) as subcategory and when on same time if i clicked on another category Unemployee check box i have to display all sub categorys under unEmpolyee . i.e when on checking on all categorys (Empolyee And Unemployee), I have to bind all sub categories Under Selected Categoys(Empolyee And Unemployee).
how i identify on saving check boxes which are selected of subcategory under which category
?
One of the way if you are using CheckBoxLists is to store path in Value in every ListItem and then read this information to identify parents.
It looks like this^

<asp:checkboxlist id="Parents" runat="server" >
<asp:listitem text="Employees" value="1">
<asp:listitem text="Unemployees" value="2">

        
<asp:checkboxlist id="Childs" runat="server" >
<asp:listitem text="Company1 Employees" value="1/1">  
<asp:listitem text="Company2 Employees" value="1/2">

        
<asp:checkboxlist id="Company1Employees" runat="server" >
<asp:listitem text="Peter" value="1/1/1">
<asp:listitem text="Pavel" value="1/1/2">


If it will help you please vote my answer.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900