views:

385

answers:

4

Hi,

I have 2 database tables named Categories and SubCategories and I want to create an Unordered List inside my asp.net web form like a tree view like

ul li a href=""CategoryDynamicData/li ul li SubCategoryDynamicData li .. .. ..

Any algorithms for that ? I couldn't nest 2 repeaters ?

+1  A: 

Out of curiosity, why won't asp:TreeView work for you?

You could use a jQuery plugin, like the Treeview plugin. It works exactly as you described, by using ul and li to represent the tree branches and leaves.

Robert Harvey
A: 

OK It seems not the best way but here how I solved this... Hope it helps others :)

    protected void Page_Load(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        using (ProjectsDataContext dc = new ProjectsDataContext())
        {
            var categories = from cats in dc.Categories
                             select cats;

            sb.Append("<ul id=\"sitemap\" class=\"sitemap\">");

            foreach (Category c in categories)
            {
                sb.Append("<li><a href=\"ShowCategory.aspx?CategoryID="+c.CategoryID +"\">"+ c.Name+"</a>");

                var subcategories = from subs in dc.SubCategories
                                    where (subs.Category.Name == c.Name)
                                    select subs;

                sb.Append("<ul>");

                foreach (SubCategory s in subcategories)
                {
                    sb.Append("<li><a href=\"../ShowSubCategory.aspx?SubCategoryID=" + s.SubCategoryID + "\">" + s.Name + "</a></li>");
                }
                sb.Append("</ul></li>");

            }

            sb.Append("</ul>");
        }


        lala.Text = sb.ToString();
    }
Kubi
lala is my asp:literal :)
Kubi
A: 

you can display Hierarchical Data with TreeView. See following sample to bind data in treeview:
http://urenjoy.blogspot.com/2009/08/display-hierarchical-data-with-treeview.html

Brij
A: 

Maybe you can try ASTreeView, Powerful and FREE.

Features:

drag and drop

ajax add, edit, delete

dynamic loading

custom icons

three state checkbox

and many more...

http://www.astreeview.com

Weijie JIN