Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi friends,

I have a doubt how to bind drop down list. i have a table.

IdCategory NameMain Category IdWeight
1Curriculum00
2Science11
3Non-Curriculum00
4Physics22
5Acting31
6Concave Lense43

In this table the main category is denotes the subcategory which will come under that category the weight denotes that sub category level.

for the above table i want to bind drop down like this format

Curriculum
-Science
--Physics
---Concave Lense
Non-Curriculum
-Acting


Can any one know the solutions please help me. u often see this is in article posting sites. if any one have the idea tell me,

Thanks,
Posted
Comments
yesotaso 14-May-11 5:34am    
Take a look at "http://en.wikipedia.org/wiki/Closed_world_assumption". If combobox does not know what you give is a tree, that tree does not exist for it. You would need to teach (simply code it in the way you want to see) it or it will interpret data the way it knows - a simple list of unordered strings.
Wonde Tadesse 14-May-11 13:58pm    
Can you elaborate your main category,sub category and sub-sub category( if any) ? It's not clear how you normalize your table.Curriculum and Non-Curriculum have the same main category id. How ?

Follow the below steps :

* Extract the Information you want to bind the DropDowlList with, by making use of SqlConnection SqlDataAdapter and DataSet.

* Use the following steps to bing the Data to the DropDownList
C#
DropDownList1.DataSource = dataSetName
DropDownList1.DataTextField = "FieldName";
DropDownList1.DataValueField = "FieldName";
DropDownList1.DataBind();



If you want to set a default value to the DropDownList from the Bind values you can use the DropDownList1.SelectedValue property.


BR//
Harsha
 
Share this answer
 
v2
Comments
Mahendra.p25 14-May-11 5:12am    
he needs Data in this

Curriculum
-Science
--Physics
---Concave Lense
Non-Curriculum
-Acting
Format
ZeeroC00l 14-May-11 5:17am    
Yes. I have seen that.. That is why I havent mentioned any code as to how you can get the detail in that format. I just mentioned how to link the obtained data to DropDownList. I am trying to get the details in the format.
sathya.spidy 14-May-11 5:30am    
i know the binding code. but i need in that format.
sathya.spidy 14-May-11 5:30am    
ya you are correct. i need the output in that format.
ZeeroC00l 14-May-11 5:44am    
I don't Have sql installed, so I can give you an idea as to how you can do this.
Looking at the Table you mentioned, you want as many - as the number of weight of the course.
Use RIGHT / LEFT operator to get the number of - 's as in the weight column and then concatenate it with the category name field.
hi,

put an extra field in database as arrangeOrder and when you fetch data write to get orderBy arrangeOrder
 
Share this answer
 
Comments
sathya.spidy 14-May-11 5:50am    
can you please explain in detail format. because my subcategory will extend to 'n' numbers.

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