For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
-
kastnerd
- Commodore (COMO)

- Posts: 474
- Joined: Wed Oct 22, 2008 9:17 am
Post
by kastnerd » Tue Apr 28, 2009 7:53 am
I have edited the left cat nav to display the main categories. But 2 of my categories have sub categories.
http://67.225.187.60/Category.aspx?CategoryId=18
I want to make a left_cat_nav_rims that will just list the sub categories under rims. I would edit the pages i want to display this expanded list on. Im just not sure what code to edit.
Code: Select all
[[ConLib:nt_SimpleCategoryList CategoryId="11" ]]
<div class="bg-nav-title">WHEELS</div>
[[ConLib:nt_SimpleCategoryList CategoryId="7" ]]
<div class="bg-nav-title">TIRES</div>
[[ConLib:nt_SimpleCategoryList CategoryId="9" ]]
<div class="bg-nav-title">OTHER ITEMS</div>
[[ConLib:nt_SimpleCategoryList CategoryId="15" ]]
Code: Select all
<%@ Control Language="C#" CodeFile="nt_SimpleCategoryList.ascx.cs" Inherits="ConLib_SimpleCategoryList" EnableViewState="false" %>
<%--
<conlib>
<summary>A simple category list which shows the nested categories under a specific category.</summary>
<param name="CssClass" default="section">Css style sheet class.</param>
<param name="HeaderCssClass" default="header">Css style sheet class.</param>
<param name="HeaderText" default="Categories">Title Text for the header.</param>
<param name="ContentCssClass" default="content">Css style sheet class.</param>
</conlib>
--%>
<asp:Panel ID="MainPanel" runat="server" CssClass="section">
<!--
<asp:Panel ID="HeaderPanel" runat="server" CssClass="header">
<h2 class="header"><asp:Localize ID="HeaderTextLabel" runat="server" Text="Categories"></asp:Localize></h2>
</asp:Panel>
-->
<asp:Panel ID="ContentPanel" runat="server" CssClass="content">
<asp:Repeater ID="CategoryList" runat="server">
<HeaderTemplate>
<ul class="category">
</HeaderTemplate>
<ItemTemplate>
<li><asp:HyperLink ID="CategoryLink" runat="server" Text='<%#Eval("Name")%>' NavigateUrl='<%#Eval("NavigateUrl")%>'></asp:HyperLink></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</asp:Panel>
-
mazhar
- Master Yoda

- Posts: 5084
- Joined: Wed Jul 09, 2008 8:21 am
-
Contact:
Post
by mazhar » Tue Apr 28, 2009 9:14 am
First update your ascx file as below
Code: Select all
<%@ Control Language="C#" CodeFile="nt_SimpleCategoryList.ascx.cs" Inherits="ConLib_SimpleCategoryList" EnableViewState="false" %>
<%--
<conlib>
<summary>A simple category list which shows the nested categories under a specific category.</summary>
<param name="CssClass" default="section">Css style sheet class.</param>
<param name="HeaderCssClass" default="header">Css style sheet class.</param>
<param name="HeaderText" default="Categories">Title Text for the header.</param>
<param name="ContentCssClass" default="content">Css style sheet class.</param>
</conlib>
--%>
<asp:Panel ID="MainPanel" runat="server" CssClass="section">
<!--
<asp:Panel ID="HeaderPanel" runat="server" CssClass="header">
<h2 class="header"><asp:Localize ID="HeaderTextLabel" runat="server" Text="Categories"></asp:Localize></h2>
</asp:Panel>
-->
<asp:Panel ID="ContentPanel" runat="server" CssClass="content">
<asp:Repeater ID="CategoryList" runat="server">
<HeaderTemplate>
<ul class="category">
</HeaderTemplate>
<ItemTemplate>
<%#GetItem(Container.DataItem)%>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</asp:Panel>
and then add following function to your ascx.cs file
Code: Select all
protected string GetItem(Object dataItem)
{
string listItem = "<li><a href='{0}'>{1}</a>{2}</li>";
Category category = (Category)dataItem;
string subUl = string.Empty;
string subListItems = string.Empty;
if (category.Name == "Sample Category")
{
CategoryCollection subCategories = CategoryDataSource.LoadForParent(category.CategoryId, true);
foreach (Category subCategory in subCategories)
subListItems += string.Format(listItem, Page.ResolveClientUrl(subCategory.NavigateUrl), subCategory.Name, string.Empty);
subUl = string.Format("<ul>{0}</ul>",subListItems);
}
listItem = string.Format(listItem,Page.ResolveClientUrl(category.NavigateUrl),category.Name,(string.IsNullOrEmpty(subUl))?string.Empty:subUl);
return listItem;
}
-
kastnerd
- Commodore (COMO)

- Posts: 474
- Joined: Wed Oct 22, 2008 9:17 am
Post
by kastnerd » Tue Apr 28, 2009 10:19 am
Thanks but I tried but failed
My ascx.cs looks like this and im not sure where to add it. I tried at the end but i got an error.
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.Marketing;
using CommerceBuilder.Orders;
using CommerceBuilder.Utility;
using CommerceBuilder.Catalog;
using CommerceBuilder.Products;
public partial class ConLib_SimpleCategoryList : System.Web.UI.UserControl
{
private string _CssClass;
private string _HeaderCssClass;
private string _HeaderText;
private string _ContentCssClass;
private int _CategoryId = -1;
public int CategoryId
{
get { return _CategoryId; }
set { _CategoryId = value; }
}
[Personalizable(), WebBrowsable()]
public string CssClass
{
get { return _CssClass; }
set { _CssClass = value; }
}
[Personalizable(), WebBrowsable()]
public string HeaderCssClass
{
get { return _HeaderCssClass; }
set { _HeaderCssClass = value; }
}
[Personalizable(), WebBrowsable()]
public string HeaderText
{
get { return _HeaderText; }
set { _HeaderText = value; }
}
[Personalizable(), WebBrowsable()]
public string ContentCssClass
{
get { return _ContentCssClass; }
set { _ContentCssClass = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(CssClass)) MainPanel.CssClass = CssClass;
if (!string.IsNullOrEmpty(HeaderCssClass)) HeaderPanel.CssClass = HeaderCssClass;
if (!string.IsNullOrEmpty(HeaderText)) HeaderTextLabel.Text = HeaderText;
if (!string.IsNullOrEmpty(ContentCssClass)) ContentPanel.CssClass = ContentCssClass;
if (_CategoryId < 0) _CategoryId = PageHelper.GetCategoryId();
CategoryList.DataSource = CategoryDataSource.LoadForParent(_CategoryId, true);
CategoryList.DataBind();
}
}
-
mazhar
- Master Yoda

- Posts: 5084
- Joined: Wed Jul 09, 2008 8:21 am
-
Contact:
Post
by mazhar » Tue Apr 28, 2009 10:23 am
What is the error?
-
kastnerd
- Commodore (COMO)

- Posts: 474
- Joined: Wed Oct 22, 2008 9:17 am
Post
by kastnerd » Tue Apr 28, 2009 10:30 am
Code: Select all
[[ConLib:nt_SimpleCategoryList2 CategoryId="9" ]] c:\Inetpub\vhosts\notubes.com\httpdocs\ConLib\nt_SimpleCategoryList2.ascx(25): error CS0103: The name 'GetItem' does not exist in the current context
-
mazhar
- Master Yoda

- Posts: 5084
- Joined: Wed Jul 09, 2008 8:21 am
-
Contact:
Post
by mazhar » Tue Apr 28, 2009 10:31 am
Here is my modified Simple List files. All you need is to edit the .cs file and update following statement
Code: Select all
if (category.Name == "Sample Category")
with your category name for example
-
kastnerd
- Commodore (COMO)

- Posts: 474
- Joined: Wed Oct 22, 2008 9:17 am
Post
by kastnerd » Tue Apr 28, 2009 11:58 am
Thanks
-
flattmatt
- Lieutenant, Jr. Grade (LT JG)

- Posts: 25
- Joined: Mon May 25, 2009 4:02 pm
Post
by flattmatt » Sat Jun 06, 2009 2:55 pm
Hello
I used this code and it works great on my site - only thing:
When I want to apply it to a subcategory, for example - I have it on this:
Browse All
----DVDS
----CDS
----Books
But when I try to use it for a second level
Browse All
----DVDS
---------Singles
---------Sets
----CDS
----Books
It won't work on a sub-category.
I set the category to DVDs - but if it's not a 1st level category, it just displays the root.
Thanks.
-
mazhar
- Master Yoda

- Posts: 5084
- Joined: Wed Jul 09, 2008 8:21 am
-
Contact:
Post
by mazhar » Mon Jun 08, 2009 5:23 am
Its because this mod was made to only take care of single root category. You may need to put some recursive code to expand all nodes of a category.
-
flattmatt
- Lieutenant, Jr. Grade (LT JG)

- Posts: 25
- Joined: Mon May 25, 2009 4:02 pm
Post
by flattmatt » Mon Jun 08, 2009 9:23 am
I'm not very good with ASP coding at all - any ideas of where I'd add the recursive code?
Here is where I think I'd do it - but not sure what to do.
Code: Select all
protected string GetItem(Object dataItem)
{
string listItem = "<li><a href='{0}'>{1}</a>{2}</li>";
Category category = (Category)dataItem;
string subUl = string.Empty;
string subListItems = string.Empty;
if (category.Name == "DVDs")
{
CategoryCollection subCategories = CategoryDataSource.LoadForParent(category.CategoryId, true);
foreach (Category subCategory in subCategories)
subListItems += string.Format(listItem, Page.ResolveClientUrl(subCategory.NavigateUrl), subCategory.Name, string.Empty);
subUl = string.Format("<ul>{0}</ul>",subListItems);
}
listItem = string.Format(listItem,Page.ResolveClientUrl(category.NavigateUrl),category.Name,(string.IsNullOrEmpty(subUl))?string.Empty:subUl);
return listItem;
}
Basically, this just needs to expand
Browse All
----DVDS
--------Singles
--------Sets
Thanks!