Can't see the option myself for paging, in fact the:
//TODO implement paging
if (!Page.IsPostBack)
{
BindData();
}
would suggest perhaps this did not make it into this release.
Obviously, the ideal solution is to perform the paging at the stored proc level for best performance.
As I am sure this is being worked on already, I started working on a quick solution but could do with some help finishing it off.
Paging using the asp:DataPager controlThis will look better but as stated isn't the best performing solution. I got as far as the below:
1) Make a copy of /Templates/Categories/ProductsInGrid.ascx. Call it NewProductsInGrid.ascx
2) Open up NewProductsInGrid.ascx and replace:
<div class="ProductGrid">
<asp:DataList ID="dlProducts" runat="server" RepeatColumns="2" RepeatDirection="Horizontal"
RepeatLayout="Table" ItemStyle-CssClass="ItemBox">
<ItemTemplate>
<nopCommerce:ProductBox1 ID="ctrlProductBox" Product='<%# Container.DataItem %>' runat="server" />
</ItemTemplate>
</asp:DataList>
</div>
with:
<div class="ProductGrid">
<asp:ListView ID="lvProducts" runat="server" GroupItemCount="2" ItemPlaceholderID="phItems"
GroupPlaceholderID="phGroups" OnPagePropertiesChanging="lvProducts_PagePropertiesChanging">
<LayoutTemplate>
<table>
<asp:PlaceHolder runat="server" ID="phGroups"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="phItems"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<nopCommerce:ProductBox1 ID="ctrlProductBox" Product='<%# Container.DataItem %>'
runat="server" />
</td>
</ItemTemplate>
</asp:ListView>
<div style="text-align: center;">
<asp:DataPager ID="dpProducts" runat="server" PageSize="4" PagedControlID="lvProducts"
QueryStringField="p">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
</div>
</div>
(here we have effectively replaced the datalist with a listview control - we use the GroupItemCount property to set the number of columns to display)
3) Open up NewProductsInGrid.ascx.cs and replace all occurrences of "dlProducts" with "lvProducts":
if (productCollection.Count > 0)
{
lvProducts.DataSource = productCollection;
lvProducts.DataBind();
}
else
lvProducts.Visible = false;
4) Add the following method to the code behind:
protected void lvProducts_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
dpProducts.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
BindData();
}
5) Save the files then go into Administration and create a new template pointing this new control. Then set a category of your choice to use this new template.
If you try and browse via the normal category link you will get an exception.
To fix I had to change:
<add name="CategoryDetailsRewrite" virtualUrl="^~/Category/([0-9]*)-([\w-]*)\.aspx(?:\?(.*))?"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/Category.aspx?CategoryID=$1&$3"
ignoreCase="true" />
in web.config to:
<add name="CategoryDetailsRewrite" virtualUrl="^~/Category/([0-9]*)-([\w-]*)\.aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/Category.aspx?CategoryID=$1"
ignoreCase="true" />
(I am not sure of the relevance of the "(?:\?(.*))?" at the end of the existing regular expression?)
Also add the following rewrite rule:
<add name="CategoryDetailsRewriteWithPaging" virtualUrl="^~/Category/([0-9]*)-([\w-]*)\.aspx&p=([0-9]*)"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/Category.aspx?CategoryID=$1&p=$3"
ignoreCase="true" />
If you browse to the category page it should now load okay. However, clicking on the page numbers will direct back to default.aspx (because of the way the datapager links are created).
However if you append "&p=2" to your rewritten url the paging works fine e.g:
http://localhost:1453/NopCommerceWeb/Category/23-computers.aspx?p=2
The problem is that the DataPager seems to pick up the CategoryID querystring parameter when creating the links e.g:
http://localhost:1453/NopCommerceWeb/Category/23-computers.aspx?CategoryID=23&p=1
So the Url is not correctly rewritten.
I suppose to fix this you could either
a) Create another rule to map "/Category/23-computers.aspx?CategoryID=23&p=1" to "/Category/23-computers.aspx&p=1"
b) Override the numeric pager link urls in the correct format.
If someone wouldn't mind looking into doing this then we could at least have temporary paging until the next release.
Cheers,
Ben