0

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
  • My problem is to get values from db and insert it into the treeview. Commented Nov 29, 2009 at 4:41

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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();
    }

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.