Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using the table category and in that I have Three Column CatID,CatName,ParentcatId,

In ParentCatId I have to show the catId column value in Hierarchy
Posted
Comments
Oshtri Deka 24-Mar-12 6:39am    
Can you improve your question please. I don't understand what is your problem.

1 solution

With standard HTML select lists there are two ways to display hierarchy:

1. If root nodes are not selectable, you can use optgroup elements. Unfortunately, ASP.NET DropDownList does not support optgroups.

2. If root nodes are selectable, use whitespace to indent child nodes

Easiest way is to use the depth value in your resultset as:
C#
DropDownList ddl = new DropDownList();
while (rs.Read())
{
    string id = rs.GetGuid(0).ToString();
    int depth = rs.GetInt32(3);
    string text = rs.GetString(2);
    string padding = String.Concat(Enumerable.Repeat(" ", 4 * depth));
    ddl.Items.Add(new ListItem(padding + text, id));
}
 
Share this answer
 

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