views:

53

answers:

1

I'm trying to figure out the best practice to setup hierarchy data that i take from a database into some contoller that would show the hierachy. Basicly this would look like a normal tree but when you press the items that are under "chapters" you get a link to another page.

I have these tables and this is the way they are connected

Period
Courses
Subjects
Chapters

I select Period from a DropDownBox and then i want all the courses in that period to line up. Under each course would be the subject and under them are the chapers, typical hierarchy.

The tables are linked together with refrences to each other in linear way.

I have tried to use treeview to show this, but dont understand how to do it. I though i could use <ul><il> tags and do it at runtime. Reapeter or datalist, possible ?

Is it better to do this with databinding in XAML or in code ?

+1  A: 

In my experience its best to to it with li and ul. You have more control of how everything is displayed. I got the query that gives me all the records and parent and depth. Then I loop throught this data and generated the list tags.

foreach (DataRow row in navigationTable.Rows) {

            var currentDepth = int.Parse(row["depth"].ToString());

            if (lastDepth < currentDepth)
            {
                output.Append("<ul>");
                numUl++;
            }
            else if (lastDepth > currentDepth)
            {
                while (lastDepth > currentDepth)
                {
                    output.Append("</li></ul></li>");
                    numUl--;
                    lastDepth--;
                }
            }
            else if (lastDepth > -1)
            {
                output.Append("</li>");
            }

            output.AppendFormat("<li id=\"base\" class=\"class\">{3}<a>link</a>

            lastDepth = currentDepth;
        }

        for (var i = 1; i <= numUl; i++)
        {
            output.Append("</li></ul>");
        }
Ivo
if i understand this right, you have records about the depth of the items that you store in the database ?
eski
yeah, maybe it doesnt completely fit with what you need but it is an example to get an idea :)
Ivo