Adding Paging to 1.4 version

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Ok i was trying to add paging feature in nopCommerce 1.4version

This is what i did:

1) adding these things in database (from admin section)

In admin section >    Content Management   >   Localization  

I added the following:

English   Admin.BlogSettings.PostsPageSize  Posts page size:    Edit
English   Admin.BlogSettings.PostsPageSize.RangeErrorMessage  The value must be from 0 to 999999.  Edit
English   Admin.BlogSettings.PostsPageSize.RequiredErrorMessage  Post page size is required.  Edit
English   Admin.BlogSettings.PostsPageSize.Tooltip  Set the page size for posts  Edit


2) In admin section >    Configuration   >   All Settings  

I added this:

Blog.PostsPageSize    10     Edit


3) Now in Administration / Modules / BlogSettings.ascx

Added this in the end:


<td class="adminTitle">
            <nopCommerce:ToolTipLabel runat="server" ID="lblPostsPageSize" Text="<% $NopResources:Admin.BlogSettings.PostsPageSize %>"
                ToolTip="<% $NopResources:Admin.BlogSettings.PostsPageSize.Tooltip %>" ToolTipImage="~/Administration/Common/ico-help.gif" />
        </td>
        <td class="adminData">
            <nopCommerce:NumericTextBox runat="server" CssClass="adminInput" ID="txtPostsPageSize"
                RequiredErrorMessage="<% $NopResources:Admin.BlogSettings.PostsPageSize.RequiredErrorMessage %>"
                MinimumValue="0" MaximumValue="999999" Value="10" RangeErrorMessage="<% $NopResources:Admin.BlogSettings.PostsPageSize.RangeErrorMessage %>"
                ValidationGroup="BlogSettings"></nopCommerce:NumericTextBox>
        </td>



4) In  BlogSettings.ascx.cs

Changed this:


protected void BindData()
        {
            cbEnableBlog.Checked = BlogManager.BlogEnabled;
            cbAllowNotRegisteredUsersToLeaveComments.Checked = BlogManager.AllowNotRegisteredUsersToLeaveComments;
            cbNotifyAboutNewBlogComments.Checked = BlogManager.NotifyAboutNewBlogComments;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    BlogManager.BlogEnabled = cbEnableBlog.Checked;
                    BlogManager.AllowNotRegisteredUsersToLeaveComments = cbAllowNotRegisteredUsersToLeaveComments.Checked;
                    BlogManager.NotifyAboutNewBlogComments = cbNotifyAboutNewBlogComments.Checked;

                    Response.Redirect("BlogSettings.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }



To This:


protected void BindData()
        {
            cbEnableBlog.Checked = BlogManager.BlogEnabled;
            cbAllowNotRegisteredUsersToLeaveComments.Checked = BlogManager.AllowNotRegisteredUsersToLeaveComments;
            cbNotifyAboutNewBlogComments.Checked = BlogManager.NotifyAboutNewBlogComments;
            txtPostsPageSize.Value = BlogManager.PostsPageSize;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    BlogManager.BlogEnabled = cbEnableBlog.Checked;
                    BlogManager.AllowNotRegisteredUsersToLeaveComments = cbAllowNotRegisteredUsersToLeaveComments.Checked;
                    BlogManager.NotifyAboutNewBlogComments = cbNotifyAboutNewBlogComments.Checked;
                   BlogManager.PostsPageSize = txtPostsPageSize.Value;

                    Response.Redirect("BlogSettings.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }




5) Now in NopCommerceStore folder / Modules / Blog.ascx

Added this in the end:


<div class="pager">
        <nopCommerce:Pager runat="server" ID="postsPager" QueryStringProperty="p" FirstButtonText="<% $NopResources:Pager.First %>"
            LastButtonText="<% $NopResources:Pager.Last %>" NextButtonText="<% $NopResources:Pager.Next %>"
            PreviousButtonText="<% $NopResources:Pager.Previous %>" CurrentPageText="Pager.CurrentPage" />
    </div>


6) In Blog.ascx.cs


Changed This:

private void BindData()
        {
            BlogPostCollection blogPosts = BlogManager.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageID);
            rptrBlogPosts.DataSource = blogPosts;
            rptrBlogPosts.DataBind();
        }




To This:


private void BindData()
        {
            int totalRecords = 0;
            int pageSize = BlogManager.PostsPageSize;

            var blogPosts = BlogManager.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageId, pageSize, CurrentPageIndex, out totalRecords);
            if (blogPosts.Count > 0)
            {
                this.postsPager.PageSize = pageSize;
                this.postsPager.TotalRecords = totalRecords;
                this.postsPager.PageIndex = this.CurrentPageIndex;

                rptrBlogPosts.DataSource = blogPosts;
                rptrBlogPosts.DataBind();
            }
        }


public int CurrentPageIndex
        {
            get
            {
                int _pageIndex = CommonHelper.QueryStringInt(postsPager.QueryStringProperty);
                _pageIndex--;
                if (_pageIndex < 0)
                    _pageIndex = 0;
                return _pageIndex;
            }
        }




And, Changed This:


protected void rptrBlogPosts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                BlogPost blogPost = e.Item.DataItem as BlogPost;
                Literal lComments = e.Item.FindControl("lComments") as Literal;
                lComments.Text = String.Format(GetLocaleResourceString("Blog.CommentsLink"), blogPost.BlogComments.Count);
            }
        }




To This:




protected void rptrBlogPosts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var blogPost = e.Item.DataItem as BlogPost;
                var lComments = e.Item.FindControl("lComments") as Literal;
                lComments.Text = String.Format(GetLocaleResourceString("Blog.CommentsLink"), blogPost.BlogComments.Count);
            }
        }
13 years ago
After doing the above mentioned change:

I re-build my solution..

Now when i run the solution i get few errors like these:


Error  32  The name 'txtPostsPageSize' does not exist in the current context  C:\Documents and Settings\Desktop\1.4BLOG\nopCommerce1.4\NopCommerceStore\Administration\Modules\BlogSettings.ascx.cs  53  13  NopCommerceStore


Error  33  'NopSolutions.NopCommerce.BusinessLogic.Content.Blog.BlogManager' does not contain a definition for 'PostsPageSize'  C:\Documents and Settings\Desktop\1.4BLOG\nopCommerce1.4\NopCommerceStore\Administration\Modules\BlogSettings.ascx.cs  53  50  NopCommerceStore


Error  37  'NopSolutions.NopCommerce.BusinessLogic.Content.Blog.BlogManager' does not contain a definition for 'PostsPageSize'  C:\Documents and Settings\Desktop\1.4BLOG\nopCommerce1.4\NopCommerceStore\Administration\Modules\BlogSettings.ascx.cs  65  33  NopCommerceStore


Error  38  The name 'txtPostsPageSize' does not exist in the current context  C:\Documents and Settings\1.4BLOG\nopCommerce1.4\NopCommerceStore\Administration\Modules\BlogSettings.ascx.cs  65  49  NopCommerceStore


Error  31  'NopSolutions.NopCommerce.BusinessLogic.Directory.Language' does not contain a definition for 'LanguageId' and no extension method 'LanguageId' accepting a first argument of type 'NopSolutions.NopCommerce.BusinessLogic.Directory.Language' could be found (are you missing a using directive or an assembly reference?)  C:\Documents and Settings\Desktop\1.4BLOG\nopCommerce1.4\NopCommerceStore\Modules\Blog.ascx.cs  50  92  NopCommerceStore
13 years ago
anyone ?
13 years ago
anyone ?...
13 years ago
Hey,

Trying to go through this now, it's something I'm also trying to add.

Quick question, did you define this by yourself?

 var blogPosts = BlogManager.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageId, pageSize, CurrentPageIndex, out totalRecords);


I don't seem to have a definition that takes "pageSize", "CurrentPageIndex" etc.
13 years ago
Crazymik3 wrote:
Hey,

Trying to go through this now, it's something I'm also trying to add.

Quick question, did you define this by yourself?

 var blogPosts = BlogManager.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageId, pageSize, CurrentPageIndex, out totalRecords);


I don't seem to have a definition that takes "pageSize", "CurrentPageIndex" etc.


If you will review the code i posted above you will understand what changes i did - Basically, I compared blog section 1.4 version and 1.7 version and replaced code in 1.4 version just like code used in 1.7version and added all the required things in 1.4 database so that it should work like 1.7 version...

But now i am stuck with error messages that i posted above and waiting for any help from nopCommerce team or anyone from this forum...
13 years ago
Edit: Woops, I see.

I need to configure mine first so it takes those parameters and then I'll see what the problems are.

Can you possibly tell me how to do that? (What stored procs to change, what to change them to, etc)

Thanks!
13 years ago
I haven't changed any stored procedure as we are just trying to add paging feature in blog section, the blog section will work as it is.

I have posted above all the changed i made...you can take a look at it...i have mentioned each and every change step by step...
13 years ago
anyone ?

Any help would be greatly appreciated.
13 years ago
Andrei , could you please guide me with this ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.