Repeating display of subcategories with products in each

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Repeating display of subcategories with products in each

Post by jmestep » Fri Oct 10, 2008 7:07 am

I'm trying to come up with a category display page that has a display of all the subcategories with the products in each grouped by subcategories and displayed sequentially. Kind of like CategoryGrid3.ascx only instead of the repeater control across the top showing the list of categories and # of products in each, I need it like

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>&nbsp;<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>&nbsp;</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;
        }
    }
Thanks for any help
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Repeating display of subcategories with products in each

Post by mazhar » Fri Oct 10, 2008 7:51 am

Judy you can create the category + products list using nested repeater. For example

Code: Select all

<asp:Repeater ID="SubCategoryRepeater" runat="server" EnableViewState="false">
                            <SeparatorTemplate>, </SeparatorTemplate>
                            <ItemTemplate>
                            <asp:HyperLink ID="SubCategoryLink" runat="server" Text='<%#String.Format("{0} ({1})", Eval("Name"), Eval("ProductCount"))%>' NavigateUrl='<%#Eval("NavigateUrl")%>'></asp:HyperLink>
                            <asp:Repeater ID="SubCategoryProductRepeater" runat="server" EnableViewState="false" DataSource='<%# LoadProducts(Eval("CategoryId"))%>'>
                            <ItemTemplate>
                            <%#Eval("Name") %>
                            </ItemTemplate>
                            </asp:Repeater>    
                            </ItemTemplate>
                        </asp:Repeater>
and in the CS file

Code: Select all

protected Object LoadProducts(Object dataItem)
    {
        int categoryId = AlwaysConvert.ToInt(dataItem);
        return ProductList.DataSource = ProductDataSource.NarrowSearch("", categoryId, 0, 0, 0, "");
    }

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Repeating display of subcategories with products in each

Post by jmestep » Fri Oct 10, 2008 1:59 pm

Thanks, I will look at that. I did Google nested datalist and nested repeater and found some examples, but this will be better. I just didn't know what to search for until this morning. I had tried to think of something already in Able that I could use for a pattern and finally thought of the PrintInvoice.aspx. It's got a gridview within a repeater, so I think this will send me in the right direction.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Repeating display of subcategories with products in each

Post by mazhar » Sat Oct 11, 2008 4:39 am

Thanks, I will look at that. I did Google nested datalist and nested repeater and found some examples, but this will be better. I just didn't know what to search for until this morning. I had tried to think of something already in Able that I could use for a pattern and finally thought of the PrintInvoice.aspx. It's got a gridview within a repeater, so I think this will send me in the right direction.
Yes its better to always look first in the existing Able code for help.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Repeating display of subcategories with products in each

Post by jmestep » Tue Oct 14, 2008 2:52 pm

I'm still trying to get this to work, but what does this do?
protected Object LoadProducts(Object dataItem)
{
int categoryId = AlwaysConvert.ToInt(dataItem);
return ProductList.DataSource = ProductDataSource.NarrowSearch("", categoryId, 0, 0, 0, "");
}

There is already a ProductList.DataSource in the .cs file and that is what the id is for the datalist display on the CategoryGrid3.ascx.
I am trying to wrap that datalist in the repeater, but can't get them to synch together.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Repeating display of subcategories with products in each

Post by mazhar » Wed Oct 15, 2008 6:46 am

That was just a sample that how you can use nested controls. If you are trying to wrap the datalist inside the repeater then perhaps you need to change the statements like

Code: Select all

ProductList.DataSource = ProductDataSource.NarrowSearch(_Keywords, this.CategoryId, _ManufacturerId, 0, 0, _PageSize, (_HiddenPageIndex * _PageSize), SortResults.SelectedValue);
because when repeater repeats the contents then there could be multiple datalist instances and probably you need to set the datasource for each datalist in each single iteration so that you can set the proper datasource for each child datalist. Have a look and check that how i set the child repeater datasource in above sample.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Repeating display of subcategories with products in each

Post by jmestep » Wed Oct 15, 2008 3:13 pm

In one of my many iterations, too many to count, I did change the NarrowSearch(_Keywords, this.CategoryId to NarrowSearch(_Keywords, category.CategoryId and it picked up only the products in the last subcategory, so I think I've still got something wrong with my nesting. One of these days, I'll go Duh---why did it take me that long to figure it out?
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Post Reply