Ok, maybe there is something else preventing the description from displaying.
Here is the full code:
Code: Select all
<%@ Control Language="C#" AutoEventWireup="True" Inherits="AbleCommerce.ConLib.CategoryGridPage2" Codebehind="CategoryGridPage2.ascx.cs" %>
<%--
<conlib>
<summary>A category page that displays all products in a grid format.</summary>
<param name="Cols" default="3">The number of columns to display</param>
<param name="PagingLinksLocation" default="BOTTOM">Indicates where the paging links will be displayd, possible values are "TOP", "BOTTOM" and "TOPANDBOTTOM".</param>
<param name="DisplayBreadCrumbs" default="True">Indicates wheather the breadcrumbs should be displayed or not, default value is true.</param>
<param name="DefaultCaption" default="Catalog">Caption text that will be shown as caption when root category will be browsed.</param>
</conlib>
--%>
<%@ Register Src="~/ConLib/CategoryBreadCrumbs.ascx" TagName="CategoryBreadCrumbs" TagPrefix="uc" %>
<%@ Register Src="~/ConLib/CategorySearchSidebar.ascx" TagName="CategorySearchSidebar" TagPrefix="uc" %>
<%@ Register Src="~/ConLib/Utility/ProductPrice.ascx" TagName="ProductPrice" TagPrefix="uc" %>
<%@ Register Src="~/ConLib/AddToCartLink.ascx" TagName="AddToCartLink" TagPrefix="uc" %>
<%@ Register src="~/ConLib/Utility/ProductItemDisplay.ascx" tagname="ProductItemDisplay" tagprefix="uc1" %>
<%@ Register src="~/ConLib/Utility/WebpageItemDisplay.ascx" tagname="WebpageItemDisplay" tagprefix="uc2" %>
<%@ Register src="~/ConLib/Utility/LinkItemDisplay.ascx" tagname="LinkItemDisplay" tagprefix="uc3" %>
<%@ Register src="~/ConLib/Utility/CategoryItemDisplay.ascx" tagname="CategoryItemDisplay" tagprefix="uc4" %>
<div id="categoryGridPage2">
<div class="section">
<uc:CategoryBreadCrumbs id="CategoryBreadCrumbs1" runat="server" HideLastNode="false" />
</div>
<asp:PlaceHolder ID="SubCategoryPanel" runat="server" EnableViewState="false">
<div class="section subCategories">
<div class="content">
<h2>Refine your search: <!--<asp:Literal ID="Caption" runat="server" EnableViewState="False"></asp:Literal> !-->
<asp:Repeater ID="SubCategoryRepeater" runat="server" EnableViewState="false">
<ItemTemplate>
<span><asp:HyperLink ID="SubCategoryLink" runat="server" Text='<%#String.Format("{0} ({1})", Eval("Name"), Eval("ProductCount"))%>' NavigateUrl='<%#Eval("NavigateUrl")%>'></asp:HyperLink></span>
</ItemTemplate>
</asp:Repeater></h2>
</asp:PlaceHolder>
<asp:PlaceHolder ID="CategoryDescriptionPanel" runat="server" EnableViewState="false">
<asp:Literal ID="CategoryDescription" runat="server" EnableViewState="false" />
</asp:PlaceHolder>
<asp:Panel ID="SummaryPanel" runat="server" CssClass="summary">
<asp:Label ID="CategorySummary" runat="server"></asp:Label>
</asp:Panel>
<asp:UpdatePanel ID="SearchResultsAjaxPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="section searchSortHeader">
<div class="content">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
<td align="left">
<div class="sortPanel">
<asp:Label ID="SortResultsLabel" runat="server" Text="Sort:" CssClass="fieldHeader" EnableViewState="false" AssociatedControlID="SortResults"></asp:Label>
<asp:DropDownList ID="SortResults" runat="server" AutoPostBack="true" CssClass="sorting" EnableViewState="false">
<asp:ListItem Text="Featured" Value="IsFeatured DESC, OrderBy ASC, Name ASC"></asp:ListItem>
<asp:ListItem Text="By Name (A -> Z)" Value="Name ASC"></asp:ListItem>
<asp:ListItem Text="By Name (Z -> A)" Value="Name DESC"></asp:ListItem>
<asp:ListItem Text="By Price (Low to High)" Value="Price ASC"></asp:ListItem>
<asp:ListItem Text="By Price (High to Low)" Value="Price DESC"></asp:ListItem>
<asp:ListItem Text="By Manufacturer (A -> Z)" Value="Manufacturer ASC"></asp:ListItem>
<asp:ListItem Text="By Manufacturer (Z -> A)" Value="Manufacturer DESC"></asp:ListItem>
</asp:DropDownList>
<asp:Panel ID="PageSizePanel" runat="server" CssClass="pageSizePanel">
<asp:Label ID="PageSizeLabel" runat="server" Text="Display:" CssClass="fieldHeader" AssociatedControlID="PageSizeOptions"></asp:Label>
<asp:DropDownList ID="PageSizeOptions" runat="server" AutoPostBack="true" CssClass="pageSizeOptions" EnableViewState="false">
<asp:ListItem Text="12 Items" Value="12"></asp:ListItem>
<asp:ListItem Text="24 Items" Value="24" Selected="True"></asp:ListItem>
<asp:ListItem Text="48 Items" Value="48"></asp:ListItem>
</asp:DropDownList>
</asp:Panel></div>
</td>
<td align="right" style="padding-right:10px;">
<span><asp:Localize ID="ResultIndexMessage" runat="server" Text="Displaying {0} - {1} of {2} results" EnableViewState="false"></asp:Localize></span>
</td>
</tr>
</table>
</div>
</div>
<asp:PlaceHolder ID="phCategoryContents" runat="server">
<div class="catalogWrapper" style="margin-right:200px;">
<asp:PlaceHolder ID="PagerPanelTop" runat="server">
<div class="pagingPanel">
<asp:Repeater ID="PagerControlsTop" runat="server" OnItemCommand="PagerControls_ItemCommand" EnableViewState="true">
<ItemTemplate>
<a class='<%#Eval("TagClass")%>' href='<%#Eval("NavigateUrl")%>'><%#Eval("Text")%></a>
</ItemTemplate>
</asp:Repeater>
</div>
</asp:PlaceHolder>
<div class="categoryGridListing2">
<div class="itemListingContainer">
<asp:DataList ID="CatalogNodeList" runat="server" Cols="4" RepeatDirection="Horizontal" Width="100%"
DataKeyField="ProductId" CssClass="itemListing" EnableViewState="true" HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="center" VerticalAlign="bottom" CssClass="tableNode" />
<ItemTemplate>
<div class="itemContainer" id="category-thumbs">
<uc1:ProductItemDisplay ID="ProductItem" runat="server" ShowName="false" ShowRating="false" ShowAddToCart="false" ShowSummary="true" Item='<%#Container.DataItem%>' ShowManufacturer="false" ShowImage="true" ImageType="IMAGE" />
</div>
</ItemTemplate>
</asp:DataList>
</div>
</div>
<asp:PlaceHolder ID="PagerPanel" runat="server">
<div class="pagingPanel" id="cat-page">
<asp:Repeater ID="PagerControls" runat="server" OnItemCommand="PagerControls_ItemCommand" EnableViewState="true">
<ItemTemplate>
<a class='<%#Eval("TagClass")%>' href='<%#Eval("NavigateUrl")%>'><%#Eval("Text")%></a>
</ItemTemplate>
</asp:Repeater>
</div>
</asp:PlaceHolder>
<asp:HiddenField ID="HiddenPageIndex" runat="server" Value="0" />
</asp:PlaceHolder>
<asp:PlaceHolder ID="phEmptyCategory" runat="server" Visible="false" EnableViewState="false">
<div class="noResultsPanel">
<asp:Localize ID="EmptyCategoryMessage" runat="server" Text="The category is empty." EnableViewState="false"></asp:Localize>
</div>
</asp:PlaceHolder>
<asp:PlaceHolder ID="phNoSearchResults" runat="server" Visible="false" EnableViewState="false">
<div class="noResultsPanel">
<asp:Localize ID="NoSearchResults" runat="server" Text="No products match your search criteria." EnableViewState="false"></asp:Localize>
</div>
</asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
And the codebehind:
Code: Select all
namespace AbleCommerce.ConLib
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AjaxControlToolkit;
using CommerceBuilder.Catalog;
using CommerceBuilder.Common;
using CommerceBuilder.Products;
using CommerceBuilder.Utility;
using CommerceBuilder.DomainModel;
[Description("A category page that displays all products in a grid format.")]
public partial class CategoryGridPage2 : System.Web.UI.UserControl
{
private int _pageSize;
private Category _category;
private IList<Product> _contentNodes;
private int _hiddenPageIndex;
private int _searchResultCount;
private int _lastPageIndex;
private int _cols = 4;
// [Browsable(true), DefaultValue(4)]
// [Description("The number of columns to display")]
// public int Cols
// {
// get { return _cols; }
// set { _cols = value; }
// }
private string _PagingLinksLocation = "TOPANDBOTTOM";
/// <summary>
/// Indicates where the paging links will be displayd, possible values are "TOP", "BOTTOM" and "TOPANDBOTTOM"
/// </summary>
[Personalizable(), WebBrowsable()]
[Browsable(true), DefaultValue("BOTTOM")]
[Description("Indicates where the paging links will be displayd, possible values are \"TOP\", \"BOTTOM\" and \"TOPANDBOTTOM\".")]
public string PagingLinksLocation
{
get { return _PagingLinksLocation; }
set
{
// possible values are "TOP", "BOTTOM" and "TOPANDBOTTOM"
String tmpLocation = value.ToUpperInvariant();
if (tmpLocation == "TOP" || tmpLocation == "BOTTOM" || tmpLocation == "TOPANDBOTTOM")
{
_PagingLinksLocation = tmpLocation;
}
}
}
private bool _DisplayBreadCrumbs = true;
/// <summary>
/// Indicates wheather the breadcrumbs should be displayed or not, default value is true
/// </summary>
[Personalizable(), WebBrowsable()]
[Browsable(true), DefaultValue(true)]
[Description("Indicates wheather the breadcrumbs should be displayed or not, default value is true.")]
public bool DisplayBreadCrumbs
{
get { return _DisplayBreadCrumbs; }
set { _DisplayBreadCrumbs = value; }
}
private string _defaultCaption = "Catalog";
/// <summary>
/// Caption text that will be shown when root category will be browsed
/// </summary>
[Personalizable(), WebBrowsable()]
[Browsable(true), DefaultValue("Catalog")]
[Description("Caption text that will be shown as caption when root category will be browsed.")]
public string DefaultCaption
{
get { return _defaultCaption; }
set { _defaultCaption = value; }
}
public int CategoryId
{
get
{
if (ViewState["CategoryId"] == null)
ViewState["CategoryId"] = AbleCommerce.Code.PageHelper.GetCategoryId();
return (int)ViewState["CategoryId"];
}
set
{
ViewState["CategoryId"] = value;
}
}
private void BindPage()
{
CategoryBreadCrumbs1.Visible = DisplayBreadCrumbs;
CategoryBreadCrumbs1.CategoryId = this.CategoryId;
//BIND THE DISPLAY ELEMENTS
if (IsValidCategory())
{
if (_category != null)
{
Page.Title = _Category.Name;
Caption.Text = _Category.Name;
if (!string.IsNullOrEmpty(_Category.Description))
{
CategoryDescriptionPanel.Visible = true;
CategoryDescription.Text = _Category.Description;
}
else CategoryDescriptionPanel.Visible = false;
}
else
{
// IF IT IS ROOT CATEGORY
Page.Title = DefaultCaption;
Caption.Text = DefaultCaption;
CategoryDescriptionPanel.Visible = true;
}
}
else
{
CategoryHeaderPanel.Visible = true;
}
BindSearchResultsPanel();
}
private bool _PagingVarsInitialized = false;
private void InitializePagingVars(bool forceRefresh)
{
Trace.Write("Initialize Paging Vars");
if (!_PagingVarsInitialized || forceRefresh)
{
_HiddenPageIndex = AlwaysConvert.ToInt(HiddenPageIndex.Value);
_searchResultCount = ProductDataSource.CountForCategory(true, this.CategoryId, false, true);
_LastPageIndex = ((int)Math.Ceiling(((double)_searchResultCount / (double)_pageSize))) - 1;
_PagingVarsInitialized = true;
}
}
protected void Page_Init(object sender, System.EventArgs e)
{
Trace.Write(this.GetType().ToString(), "Load Begin");
_Category = CategoryDataSource.Load(this.CategoryId);
//EXIT PROCESSING IF CATEGORY IS INVALID OR MARKED PRIVATE
if (!IsValidCategory())
{
SearchResultsAjaxPanel.Visible = false;
}
else
{
if (_Category != null)
{
//REGISTER THE PAGEVISIT
AbleCommerce.Code.PageVisitHelper.RegisterPageVisit(_Category.Id, CatalogNodeType.Category, _Category.Name);
}
if (!Page.IsPostBack)
{
//INITIALIZE SEARCH CRITERIA ON FIRST VISIT
_HiddenPageIndex = AlwaysConvert.ToInt(Request.QueryString["p"]);
string tempSort = Request.QueryString["s"];
if (!string.IsNullOrEmpty(tempSort))
{
ListItem item = SortResults.Items.OfType<ListItem>().SingleOrDefault(x => string.Compare(x.Value, tempSort, StringComparison.InvariantCultureIgnoreCase) == 0);
if (item != null) item.Selected = true;
}
}
Trace.Write(this.GetType().ToString(), "Load Complete");
}
}
protected void BindSubCategories()
{
IList<Category> allCategories = CategoryDataSource.LoadForParent(this.CategoryId, true);
List<SubCategoryData> populatedCategories = new List<SubCategoryData>();
foreach (Category category in allCategories)
{
int productCount = ProductDataSource.CountForCategory(true, category.Id, true, true);
if (productCount > 0)
{
populatedCategories.Add(new SubCategoryData(category.Id, category.Name, category.NavigateUrl, productCount));
}
}
if (populatedCategories.Count > 0)
{
SubCategoryPanel.Visible = true;
SubCategoryRepeater.DataSource = populatedCategories;
SubCategoryRepeater.DataBind();
}
else SubCategoryPanel.Visible = false;
}
public class SubCategoryData
{
private int _CategoryId;
private string _Name;
private int _ProductCount;
private string _NavigateUrl;
public int CategoryId { get { return _CategoryId; } }
public string Name { get { return _Name; } }
public int ProductCount { get { return _ProductCount; } }
public string NavigateUrl { get { return _NavigateUrl; } }
public SubCategoryData(int categoryId, string name, string navigateUrl, int productCount)
{
_CategoryId = categoryId;
_Name = name;
_NavigateUrl = navigateUrl;
_ProductCount = productCount;
}
}
private void BindSearchResultsPanel()
{
Trace.Write(this.GetType().ToString(), "Begin Bind Search Results");
if (_ContentNodes.Count > 0)
{
phCategoryContents.Visible = true;
//INITIALIZE PAGING VARIABLES
InitializePagingVars(false);
//BIND THE RESULT PANE
BindResultHeader();
//BIND THE PAGING CONTROLS FOOTER
BindPagingControls();
}
else
{
ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, 0, 0, 0);
//HIDE THE CONTENTS
phCategoryContents.Visible = false;
phEmptyCategory.Visible = (_Category != null && _Category.CatalogNodes.Count == 0);
phNoSearchResults.Visible = !phEmptyCategory.Visible;
}
//UPDATE AJAX PANEL
SearchResultsAjaxPanel.Update();
Trace.Write(this.GetType().ToString(), "End Bind Search Results");
}
protected void BindResultHeader()
{
//UPDATE THE RESULT INDEX MESSAGE
int startRowIndex = (_pageSize * _HiddenPageIndex);
int endRowIndex = startRowIndex + _pageSize;
if (endRowIndex > _searchResultCount) endRowIndex = _searchResultCount;
if (_searchResultCount == 0) startRowIndex = -1;
ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, _searchResultCount);
CatalogNodeList.DataSource = _ContentNodes;
CatalogNodeList.DataBind();
}
#region PagingControls
protected void BindPagingControls()
{
if (_LastPageIndex > 0)
{
PagerPanel.Visible = (PagingLinksLocation == "TOPANDBOTTOM");
PagerPanelTop.Visible = (PagingLinksLocation == "TOPANDBOTTOM");
float tempIndex = ((float)_HiddenPageIndex / 10) * 10;
int currentPagerIndex = (int)tempIndex;
int totalPages = currentPagerIndex + 1 + _pageSize; // ADD ONE BECAUSE IT IS A ZERO BASED INDEX
if (totalPages > (_LastPageIndex + 1)) totalPages = (_LastPageIndex + 1);
string baseUrl;
if (_Category != null) baseUrl = this.Page.ResolveUrl(_Category.NavigateUrl) + "?";
else if (this.CategoryId == 0) baseUrl = this.Page.ResolveUrl(Request.Url.AbsolutePath) + "?";
else baseUrl = AbleCommerce.Code.NavigationHelper.GetStoreUrl(this.Page, "Search.aspx?");
//if (!string.IsNullOrEmpty(_Keywords)) baseUrl += "k=" + Server.UrlEncode(_Keywords) + "&";
//if (_ManufacturerId != 0) baseUrl += "m=" + _ManufacturerId.ToString() + "&";
if (!String.IsNullOrEmpty(SortResults.SelectedValue)) baseUrl += "s=" + SortResults.SelectedValue + "&";
if (!string.IsNullOrEmpty(PageSizeOptions.SelectedValue))
{
baseUrl += "ps=" + PageSizeOptions.SelectedValue + "&";
}
if (PagerPanel.Visible)
{
PagerControls.DataSource = AbleCommerce.Code.NavigationHelper.GetPaginationLinks(currentPagerIndex, totalPages, baseUrl);
PagerControls.DataBind();
}
if (PagerPanelTop.Visible)
{
PagerControlsTop.DataSource = AbleCommerce.Code.NavigationHelper.GetPaginationLinks(currentPagerIndex, totalPages, baseUrl);
PagerControlsTop.DataBind();
}
}
else
{
PagerPanel.Visible = false;
PagerPanelTop.Visible = false;
}
}
protected void PagerControls_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Page")
{
InitializePagingVars(false);
_HiddenPageIndex = AlwaysConvert.ToInt((string)e.CommandArgument);
_searchResultCount = ProductDataSource.CountForCategory(true, this.CategoryId, false, true);
if (_HiddenPageIndex < 0) _HiddenPageIndex = 0;
if (_HiddenPageIndex > _LastPageIndex) _HiddenPageIndex = _LastPageIndex;
HiddenPageIndex.Value = _HiddenPageIndex.ToString();
}
}
protected void SetPagerIndex()
{
InitializePagingVars(false);
_HiddenPageIndex = AlwaysConvert.ToInt(Request.QueryString["p"]);
if (_HiddenPageIndex < 0) _HiddenPageIndex = 0;
if (_HiddenPageIndex > _LastPageIndex) _HiddenPageIndex = _LastPageIndex < 0 ? 0 : _LastPageIndex;
HiddenPageIndex.Value = _HiddenPageIndex.ToString();
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
string eventTarget = Request["__EVENTTARGET"];
if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions"))
{
string pageSizeOption = Request.QueryString["ps"];
if (!string.IsNullOrEmpty(pageSizeOption))
{
PageSizeOptions.ClearSelection();
ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption);
if (item != null) item.Selected = true;
}
}
else
if (eventTarget.EndsWith("PageSizeOptions"))
{
string url = Request.RawUrl;
if (url.Contains("?"))
url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
url += "?s=" + SortResults.SelectedValue;
url += "&ps=" + PageSizeOptions.SelectedValue;
Response.Redirect(url);
}
if (_Category != null)
{
Page.Title = string.IsNullOrEmpty(_Category.Title) ? _Category.Name : _Category.Title;
CategoryBreadCrumbs1.CategoryId = this.CategoryId;
Caption.Text = _Category.Name;
CategoryDescription.Text = _Category.Summary;
}
else
{
// IT IS ROOT CATEGORY
Page.Title = DefaultCaption;
CategoryBreadCrumbs1.CategoryId = this.CategoryId;
Caption.Text = DefaultCaption;
CategoryDescription.Text = DefaultCategorySummary;
}
_pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
SetPagerIndex();
CatalogNodeList.RepeatColumns = Cols;
if (IsValidCategory())
{
//INITIALIZE THE CONTENT NODES
_ContentNodes = new List<Product>();
IList<Product> visibleNodes = ProductDataSource.LoadForCategory(true, this.CategoryId, false, true, SortResults.SelectedValue, _pageSize, (_HiddenPageIndex * _pageSize));
if (visibleNodes.Count > 0)
{
_ContentNodes.AddRange(visibleNodes);
// DELAYED QUERIES TO EAGER LOAD RELATED DATA FOR PERFORMANCE BOOST
List<int> ids = visibleNodes.Select(p => p.Id).ToList();
var futureQuery = NHibernateHelper.QueryOver<Product>()
.AndRestrictionOn(p => p.Id).IsIn(ids)
.Fetch(p => p.Specials).Eager
.Future<Product>();
NHibernateHelper.QueryOver<Product>()
.AndRestrictionOn(p => p.Id).IsIn(ids)
.Fetch(p => p.ProductOptions).Eager
.Future<Product>();
NHibernateHelper.QueryOver<Product>()
.AndRestrictionOn(p => p.Id).IsIn(ids)
.Fetch(p => p.ProductKitComponents).Eager
.Future<Product>();
NHibernateHelper.QueryOver<Product>()
.AndRestrictionOn(p => p.Id).IsIn(ids)
.Fetch(p => p.ProductTemplates).Eager
.Future<Product>();
NHibernateHelper.QueryOver<Product>()
.AndRestrictionOn(p => p.Id).IsIn(ids)
.Fetch(p => p.Reviews).Eager
.Future<Product>();
futureQuery.ToList();
}
if (_pageSize == 0)
_pageSize = _ContentNodes.Count;
int minimumPageSize = AlwaysConvert.ToInt(PageSizeOptions.Items[0].Value);
PageSizePanel.Visible = _searchResultCount > minimumPageSize;
//BIND PAGE
BindPage();
}
int manufacturerCount = ManufacturerDataSource.CountAll();
foreach (ListItem li in SortResults.Items)
{
if (li.Value.StartsWith("Manufacturer"))
{
li.Enabled = manufacturerCount > 0;
}
}
}
private bool IsValidCategory()
{
// IF IT IS ROOT CATEGORY
if (this.CategoryId == 0) return true;
else
{
// TRY TO LOAD THE CATEGORY AGAIN
if (_Category == null) _Category = CategoryDataSource.Load(this.CategoryId);
if (_Category != null && _Category.Visibility != CatalogVisibility.Private) return true;
else return false;
}
}
}
}
I am reluctant to use CategoryGridPage4 as I have already made major modifications to the file code above.
Thanks again!
Simone