• Dynamic webpage sitemap (ex. hierarchy with all pages)

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
triplw
Commander (CMDR)
Commander (CMDR)
Posts: 144
Joined: Sat Jan 12, 2008 5:34 pm
Contact:

Re: • Dynamic webpage sitemap (ex. hierarchy with all pages)

Post by triplw » Sun Sep 11, 2011 9:56 am

I made a custom control:
SiteMap.ascx

Code: Select all

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SiteMap.ascx.cs" Inherits="ConLib_SiteMap" %>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>

<ajax:UpdatePanel ID="DescriptionAjax" runat="server">
    <ContentTemplate>
        <div class="content">

      <asp:Literal ID="CategoryLinks" runat="server"></asp:Literal>

        </div>
    </ContentTemplate>
</ajax:UpdatePanel>

and SiteMap.ascx.cs:

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Common;
using CommerceBuilder.Utility;
using CommerceBuilder.Products;
using CommerceBuilder.Catalog;

public partial class ConLib_SiteMap : System.Web.UI.UserControl
{
    static String myCategoryLinks = "";
    static int recursiveCount = 0;
    protected void Page_Init(object sender, EventArgs e)
    {

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        recursiveCount = 0;
        myCategoryLinks = "";
        CategoryLinks.Text = "";
        RecursiveLoadParents(0, "&nbsp;",20);
        CategoryLinks.Text += myCategoryLinks;
    }

    protected static void RecursiveLoadParents(int CatId, string delimeter, int fontsize)
    {
        fontsize = fontsize - 2;
        if (CatId > 0)
            delimeter = "&nbsp;&nbsp;&nbsp;&nbsp;" + delimeter;
        CategoryCollection cc = CategoryDataSource.LoadForParent(CatId, true);
        foreach (Category c in cc)
        {
            recursiveCount = recursiveCount + fontsize;
            if (recursiveCount >= 1500)
            {
                myCategoryLinks += "";
                recursiveCount = 0;
            }
            myCategoryLinks += delimeter + "<span style='font-size:" + fontsize + "px'><a href='" + c.NavigateUrl.Substring(2) + "'>" + c.Name + "</a></span><br>";
            RecursiveLoadParents(c.CategoryId, delimeter, fontsize);
        }
    }




}


Post Reply