Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2005, 02:41 PM   PM User | #1
jbezweb
New Coder

 
Join Date: Feb 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
jbezweb is an unknown quantity at this point
Dynamic Sitemap

Hi,

I need to make a dynamic sitemap for a CMS.

All pages are stored in a DB.

I have pulled all info out into these arrays

PageIds - all pages ids
PageNames - all page names
ParentPages - Parent page of corresponding page (id #'s, except 'root' indicating top level page).

(eg. PageIds[0] is a sub page of ParentPages[0], if ParentPages[0] = 'root' then it is the top, 1st, level)

I need it to support an infinate number of levels. My guess is that it needs to be done in a loop but can't seem to figure out how get it to work.

it should look like this:

Root Page
-Sub Page
-Sub Sub Page
-etc

Any help or direction is greatly appreciated.
__________________
Asp.Net 1.1 - 20 hrs
CSS 2.0 - 3 hrs
XHTML 1.1 - 5hrs
JavaScript - 5hrs
Cross-Browser Compatibility - Priceless
jbezweb is offline   Reply With Quote
Old 10-06-2005, 02:43 PM   PM User | #2
jbezweb
New Coder

 
Join Date: Feb 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
jbezweb is an unknown quantity at this point
Here is what I have so far. It worked with the first 5 values but as I added more and it got more complicated it has flaws in it.

Some pointers or direction would be appreciated.

Thanks,

Code:
@ Page Language="C#" Debug="True" %>

<html>
<head>
 <title>Group Test</title>
</head>

<body>
 <script language="C#" runat="server">

  void Page_Load()
  {
   string Html = "";
   string [] PageIds = new string[10]{"1","2","3","4","5","6","7","8","9","10"};
   string [] PageNames = new string[10]{"Homepage","About Me","Articles","Downloads","Contact Me","page6","page7","page8","page9","page10"};
   string [] ParentPages = new string[10]{"root","1","4","root","2","root","root","6","7","7"};
   int i;
   int j;
   int lvl;
   int indent;
   int currentJ;
   string currentPage = "";
   bool finished = false;

   for(i=0;i<PageIds.Length;i++)
   { 
    lvl = 1;
    indent = 0;
    if(ParentPages[i] == "root")
    {
     finished = false;
     Html += "\n\t\t<div style='width:"+indent+"px;float:left'></div>" + PageNames[i] + "<br>";
     currentPage = PageIds[i];

     while(!finished)
     {
      finished = true;

      for(j=0;j<PageIds.Length;j++)
      {
       if(currentPage == ParentPages[j])
       {
        lvl++;
        indent += 20;
        currentJ = j;
        currentPage = PageIds[currentJ];
        Html += "\n\t\t\t<div style='width:"+indent+"px;float:left'></div>" + 
        PageNames[currentJ] + "<br>";
       }
      }

      for(j=0;j<PageIds.Length;j++)
      {
       if(ParentPages[j] == currentPage)
       {
        finished = false;
       }
      }
     }
    }
   }
   Output.Text = Html;
  }

 </script>

 <form runat="server">
  <asp:Label id="Output" runat="server" />
 </form>

</body>
</html>
__________________
Asp.Net 1.1 - 20 hrs
CSS 2.0 - 3 hrs
XHTML 1.1 - 5hrs
JavaScript - 5hrs
Cross-Browser Compatibility - Priceless
jbezweb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:58 PM.


Advertisement
Log in to turn off these ads.