views:

79

answers:

2

I'm working on a CMS using VB.NET 3.5 and I'm stuck on a concept. I have different modules that do different things like wysiwyg, contact form, image gallery, etc... but one that is becoming a bit of a challenge is wrapping my head around "how" to build a sitemap.

For the record, I am NOT talking about an SEO Sitemap (XML), but rather a visitor sitemap similar to Karamasoft (Check out the BMW or the Dell style for an idea of what I'm shooting for).

My Database has the following columns

ID        ParentID        MenuName        Slug            DateUpdated

1         Null            Home            ~/home          01/01/2010
2         Null            About           ~/about         01/01/2010
3         Null            Contact         ~/contact       01/01/2010
4         2               History         ~/history       01/01/2010
5         2               Future          ~/future        01/01/2010
6         3               Jobs            ~/jobs          01/01/2010

I have my code setup in such a way that I populate all the relevant fields into an Object on the server side that I can then access multiple times without hitting the DB over and over.

    Public Shared ReadOnly Property Instance() As List(Of NavigationDataItem)
        Get
            Dim n As New List(Of NavigationDataItem)()

            If _Instance Is Nothing Then

                Dim PagesDC As New Dal.icms_PagesDataContext()
                Dim results = PagesDC.icms_Pages_GetPageMenu().ToList

                For Each o As Object In results
                    If o.isHomePage Then
                        n.Add(New NavigationDataItem(o.ID, o.ParentID, o.MenuName, "~/", o.DateUpdated))
                    Else
                        n.Add(New NavigationDataItem(o.ID, o.ParentID, o.MenuName, o.Slug, o.DateUpdated))
                    End If
                Next

                _Instance = n
            Else : n = _Instance
            End If
            Return n
        End Get
    End Property 'Instance

What I'm trying to do is have all of the records that have NO ParentID (IE: they are top level items) be listed at the top, and all of it's children listed underneath.

<table>
  <tr>
    <th>Home</th>
    <th>About</th>
    <th>Contact</th>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>History</td>
    <td>Jobs</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Future</td>
    <td>&nbsp;</td>
  </tr>
</table>

I want to be able to dynamically set the number of table columns, so that if I have 10 Parent items and only set my width to 5 columns, the remaining parent items would be listed in another table row below.

I'm sure I can build the code myself once I wrap my head around this, I'm just looking for a "concept" on how to approach this problem.

Also, I am NOT looking for a Treeview since that's basically what I'm doing now and I really don't love it at all.

A: 

Use an ASP:Table control and add cells one at a time, when you reach your desired width (5) start a new row

TFD
I realize that, however it's more complicated since I have to keep parents AND children in mind, as well as children of children.
rockinthesixstring
What is going to happen with children etc?
TFD
I edited above to show the structure I was thinking. I suppose that I could use `</br>` or `<li>Child</li>` instead of new table rows for children, but think there definitely needs to be a visual separation between Parents and Children
rockinthesixstring
+1  A: 

You could use a DataList to set the number of columns and bind that with top level items only. Then use a simple function to get the childitems for each main item and render those with a repeater:

<asp:DataList RepeatColumns="5" DataSource="<%#GetParentMenuItems()%>" runat="server">
  <ItemTemplate>
    <h1><%#Container.DataItem.MenuName%></h1>
    <hr />
    <asp:Repeater DataSource="<%#GetChildMenuItems(Container.DataItem.ID)%>" runat="server">
      <ItemTemplate>
        <a href="<%#Container.DataItem.Slug%>"><%#Container.DataItem.MenuName%></a>
        <br />
      </ItemTemplate>
    </asp:Repeater>
  </ItemTemplate>
</asp:DataList>

Ideally, the child items would be a collection hanging off the parent, then you could bind the nested repeater to that directly. You could then create a user control that renders the items, and then nest itself to render any sub-items.

On a side-note: I think you'll be doing yourself a favor by sticking to the .NET sitemap rather than cooking up your own. Lots of handy controls are using it, and it's nicely integrated with the rest of the ASP.NET framework. :)

Jakob Gade
Thanks for the detailed answer. Can you elaborate on the asp.net sitemap? I'm not looking for the "web.sitemap", so I'm not entirely sure what you're talking about.
rockinthesixstring
I just meant that from what I can tell, the functionality you're implementing is already there with the ASP.NET sitemap. If you need something more dynamic (i.e. reading the menu structure out of a database), at least consider pulling that out in the sitemap format, so it can be plugged into the ASP.NET framework. Implementing a custom Sitemap provider is pretty easy. :) http://msdn.microsoft.com/en-us/library/ms178431.aspx
Jakob Gade
But the sitemap doesn't have the ability to pull data from the database. My setup is good on the database side, just trying to nail down the page sitemap. Thanks for your answer above, I'm gonna try it a little later in the day.
rockinthesixstring