Subcategory 1
Product 1 Product 2 Product 3
Subcategory 2
Product 1 Product 2
Etc.
I'm using CategoryGrid3.ascx because they want the quantity boxes and the one add to cart button. I've stripped the code of paging, searches, header sorting, etc. With the code I have now, the datalist displays the products for the last category when there are actually 3 categories. If I replace ProductList.DataSource = ProductDataSource.NarrowSearch("", category.CategoryId, 0, 0, 0, "");
( the category.CategoryId) with a category #, it displays those fine. I just need to get it to repeat for the proper category under the category name heading.
Here is most of the code:
Code: Select all
<ajax:UpdatePanel ID="SearchResultsAjaxPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:PlaceHolder ID="CategoryHeaderPanel" runat="server" EnableViewState="false">
<uc:CategoryBreadCrumbs id="CategoryBreadCrumbs1" runat="server" HideLastNode="True" />
<div class="pageHeader">
<h1><asp:Localize ID="Caption" runat="server" EnableViewState="False"></asp:Localize></h1>
</div>
</asp:PlaceHolder>
<asp:PlaceHolder ID="SubCategoryPanel" runat="server" EnableViewState="false">
<!-- Top Bar -->
<asp:Label ID="SubCategoryName" runat="server"></asp:Label>
<div class="catalogWrapper">
<asp:DataList ID="ProductList" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" Width="100%"
OnItemDataBound="ProductList_ItemDataBound" DataKeyField="ProductId" CssClass="catalog" EnableViewState="true" HorizontalAlign="left">
<ItemStyle HorizontalAlign="center" VerticalAlign="middle" Width="33%" CssClass="tableNode" />
<ItemTemplate>
<asp:PlaceHolder ID="phItemTemplate1" runat="server"></asp:PlaceHolder>
<uc:ProductPrice ID="Price" runat="server" Product='<%#Container.DataItem%>' />
<asp:PlaceHolder ID="phItemTemplate2" runat="server"></asp:PlaceHolder>
<div id="QuantityPanel" runat="Server">
<asp:Label ID="QuantityLabel" runat="server" Text="Quantity:"></asp:Label> <asp:TextBox ID="Quantity" runat="server" Text="" MaxLength="4" Columns="3"></asp:TextBox>
<asp:HiddenField ID="HiddenProductId" runat="server" Value='<%#Eval("ProductId")%>' />
</div>
</ItemTemplate>
<SeparatorTemplate> </SeparatorTemplate>
<SeparatorStyle CssClass="separator" Width="1" />
</asp:DataList><br clear="all" />
<div align="center">
<asp:Button ID="MultipleAddToBasketButton" runat="server" Text="Add to Basket" OnClick="MultipleAddToBasketButton_Click" ToolTip="Fill in the quantity and Click this to add multiple products to baskt." />
</div>
</div>
</asp:PlaceHolder>
</ContentTemplate>
</ajax:UpdatePanel>
Code: Select all
protected void BindSubCategories()
{
CategoryCollection allCategories = CategoryDataSource.LoadForParent(this.CategoryId, true);
foreach (Category category in allCategories)
{
ProductList.DataSource = ProductDataSource.NarrowSearch("", category.CategoryId, 0, 0, 0, "");
ProductList.DataBind();
}
}
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;
}
}