Page 1 of 1

Suggestion: Put the product page index at top and bottom

Posted: Wed Dec 05, 2007 7:35 am
by AbleMods
When browsing for products in the catalog, the page number index section is only at the bottom right. It would a nice interface improvement to have those page number links both at the top and bottom of the page, same side.

Posted: Fri Dec 07, 2007 5:23 am
by sohaib
Request for enhancement posted for future revisions.

Posted: Fri Dec 07, 2007 9:51 am
by compunerdy

Code: Select all

 

 asp:Panel ID="PagerPanel" runat="server"
                div class="paging"
                    asp:Repeater ID="PagerControls" runat="server" OnItemCommand="PagerControls_ItemCommand"
                        <ItemTemplate>
                            a class='<Eval>'  href='<Eval>'><Eval>
                        </ItemTemplate>
                    /asp:Repeater
                </div>
            /asp:Panel        
This code generates the paging and you can move it to the top easily enough. I just dont know how to get it to allow you to show it at the top and the bottom. If you put the code in both spots it throws an error.

Hmmm..nevermind, it wont let me paste the code correctly. The code is not correct as I had to modify it in order for it to display here.

Posted: Fri Dec 07, 2007 12:42 pm
by jmestep
You need to click Disable HTML in this post to get it to display.
On your code, did it work if you gave the control a different ID?

Posted: Fri Dec 07, 2007 1:28 pm
by compunerdy

Code: Select all

<asp:Panel ID="PagerPanel" runat="server">
                <div class="paging">
                    <asp:Repeater ID="PagerControls" runat="server" OnItemCommand="PagerControls_ItemCommand">
                        <ItemTemplate>
                            <a class='<%#Eval("TagClass")%>'  href='<%#Eval("NavigateUrl")%>'><%#Eval("Text")%></a>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
            </asp:Panel>   
Ok here is the correct code then. I tried to name it like PagerPanel2 etc.. which made it so no errors showed but it didnt show anything either.

Posted: Fri Dec 14, 2007 5:01 am
by troutlet
Post feature requests to this forum. PLEASE VOTE on your favorite feature ideas by posting your vote to it's thread!
yes!

Posted: Thu Feb 07, 2008 1:22 pm
by batmike
In case anyone is still interested in trying this out ... or you've figured it out by now. I went through the ascx file and made two sections and then went through the ascx.cs file and duplicated the code so there's a paging event 1 and paging event 2 but they both work together on all the pages I've tested.

The only thing I would really like to do - and if anyone could help me that would be great - would be to show all the page numbers all the time, instead of replacing the previous pages with the back arrow.

Anyway here is the ascx page code:

Part 1 ... top section:

Code: Select all

        <asp:Panel ID="PagerPanel1" runat="server">
            <div class="paging">
                <asp:Repeater ID="PagerControls1" runat="server" OnItemCommand="PagerControls_ItemCommand1">
                       <ItemTemplate>
                           <a class='<%#Eval("TagClass")%>'  href='<%#Eval("NavigateUrl")%>'><%#Eval("Text")%></a>
                       </ItemTemplate>
                </asp:Repeater>
            </div>
        </asp:Panel> 
Part 2 ... bottom section:

Code: Select all

            <asp:Panel ID="PagerPanel2" runat="server">
                <div class="paging">
                    <asp:Repeater ID="PagerControls2" runat="server" OnItemCommand="PagerControls_ItemCommand2">
                        <ItemTemplate>
                            <a class='<%#Eval("TagClass")%>'  href='<%#Eval("NavigateUrl")%>'><%#Eval("Text")%></a>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
            </asp:Panel>

And here is the ascx.cs code (Just replace the code from #region PagingControls on down to the bottom of the file, except for the ending curly brace:

Code: Select all

    #region PagingControls1

    protected void BindPagingControls1()
    {
        if (_LastPageIndex > 0)
        {
            PagerPanel1.Visible = true;
            List<PagerLinkData1> pagerLinkData1 = new List<PagerLinkData1>();
            float tempIndex1 = ((float)_HiddenPageIndex / 10) * 10;
            int currentPagerIndex1 = (int)tempIndex1 ;

            int lastPagerIndex1 = currentPagerIndex1 + _PageSize;
            if (lastPagerIndex1 > _LastPageIndex) lastPagerIndex1 = _LastPageIndex;
            string baseUrl;
            if (_Category != null) baseUrl = this.Page.ResolveClientUrl(_Category.NavigateUrl) + "?";
            else baseUrl = NavigationHelper.GetStoreUrl(this.Page, "Search.aspx?");
            if (!string.IsNullOrEmpty(_Keywords)) baseUrl += "k=" + Server.UrlEncode(_Keywords) + "&";
            if (_ManufacturerId != 0) baseUrl += "m=" + _ManufacturerId.ToString() + "&";
            baseUrl += "p=";
            string navigateUrl;
            if (currentPagerIndex1 > 0)
            {
                navigateUrl = baseUrl + (currentPagerIndex1 - 1).ToString();
                pagerLinkData1.Add(new PagerLinkData1("<", navigateUrl, (currentPagerIndex1 - 1), true));
            }
            while (currentPagerIndex1 <= lastPagerIndex1)
            {
                string linkText = ((int)(currentPagerIndex1 + 1)).ToString();
                if (currentPagerIndex1 != _HiddenPageIndex)
                {
                    navigateUrl = baseUrl + currentPagerIndex1.ToString();
                    pagerLinkData1.Add(new PagerLinkData1(linkText, navigateUrl, currentPagerIndex1, (currentPagerIndex1 != _HiddenPageIndex)));
                }
                else
                {
                    navigateUrl = "#";
                    pagerLinkData1.Add(new PagerLinkData1(linkText, navigateUrl, currentPagerIndex1, (currentPagerIndex1 != _HiddenPageIndex), "current"));
                }
                currentPagerIndex1++;
            }
            if (lastPagerIndex1 < _LastPageIndex)
            {
                navigateUrl = baseUrl + (lastPagerIndex1 + 1).ToString();
                pagerLinkData1.Add(new PagerLinkData1(">", navigateUrl,lastPagerIndex1+1, true));
            }
            PagerControls1.DataSource = pagerLinkData1;
            PagerControls1.DataBind();
        }
        else
        {
            PagerPanel1.Visible = false;
        }
    }

    public class PagerLinkData1
    {
        private string _Text;
        private int _PageIndex;
        private string _NavigateUrl;
        public int PageIndex { get { return _PageIndex; } }
        private bool _Enabled;
        public string Text { get { return _Text; } }
        public string NavigateUrl { get { return _NavigateUrl; } }
        public bool Enabled { get { return _Enabled; } }
        private string _tagClass;
        public string TagClass { get { return _tagClass; } set { _tagClass = value; } } 
        public PagerLinkData1(string text, string navigateUrl,int pageIndex, bool enabled)
        {
            _Text = text;
            _NavigateUrl = navigateUrl;
            _PageIndex = pageIndex;
            _Enabled = enabled;
        }

        public PagerLinkData1(string text, string navigateUrl, int pageIndex, bool enabled,string tagClass)
        {
            _Text = text;
            _NavigateUrl = navigateUrl;
            _PageIndex = pageIndex;
            _Enabled = enabled;
            _tagClass = tagClass;
        }
    }

    protected void PagerControls_ItemCommand1(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Page")
        {
            InitializePagingVars(false);
            _HiddenPageIndex = AlwaysConvert.ToInt((string)e.CommandArgument);
            if (_HiddenPageIndex < 0) _HiddenPageIndex = 0;
            if (_HiddenPageIndex > _LastPageIndex) _HiddenPageIndex = _LastPageIndex;
            HiddenPageIndex.Value = _HiddenPageIndex.ToString();
        }
    }
    protected void SetPagerIndex1()
    {
        InitializePagingVars(false);
        _HiddenPageIndex = AlwaysConvert.ToInt(Request.QueryString["p"]);
        if (_HiddenPageIndex < 0) _HiddenPageIndex = 0;
        if (_HiddenPageIndex > _LastPageIndex) _HiddenPageIndex = _LastPageIndex;
        HiddenPageIndex.Value = _HiddenPageIndex.ToString();
    }
    #endregion

    #region PagingControls

    protected void BindPagingControls2()
    {
        if (_LastPageIndex > 0)
        {
            PagerPanel2.Visible = true;
            List<PagerLinkData2> pagerLinkData2 = new List<PagerLinkData2>();
            float tempIndex2 = ((float)_HiddenPageIndex / 10) * 10;
            int currentPagerIndex2 = (int)tempIndex2 ;

            int lastPagerIndex2 = currentPagerIndex2 + _PageSize;
            if (lastPagerIndex2 > _LastPageIndex) lastPagerIndex2 = _LastPageIndex;
            string baseUrl;
            if (_Category != null) baseUrl = this.Page.ResolveClientUrl(_Category.NavigateUrl) + "?";
            else baseUrl = NavigationHelper.GetStoreUrl(this.Page, "Search.aspx?");
            if (!string.IsNullOrEmpty(_Keywords)) baseUrl += "k=" + Server.UrlEncode(_Keywords) + "&";
            if (_ManufacturerId != 0) baseUrl += "m=" + _ManufacturerId.ToString() + "&";
            baseUrl += "p=";
            string navigateUrl;
            if (currentPagerIndex2 > 0)
            {
                navigateUrl = baseUrl + (currentPagerIndex2 - 1).ToString();
                pagerLinkData2.Add(new PagerLinkData2("<", navigateUrl, (currentPagerIndex2 - 1), true));
            }
            while (currentPagerIndex2 <= lastPagerIndex2)
            {
                string linkText = ((int)(currentPagerIndex2 + 1)).ToString();
                if (currentPagerIndex2 != _HiddenPageIndex)
                {
                    navigateUrl = baseUrl + currentPagerIndex2.ToString();
                    pagerLinkData2.Add(new PagerLinkData2(linkText, navigateUrl, currentPagerIndex2, (currentPagerIndex2 != _HiddenPageIndex)));
                }
                else
                {
                    navigateUrl = "#";
                    pagerLinkData2.Add(new PagerLinkData2(linkText, navigateUrl, currentPagerIndex2, (currentPagerIndex2 != _HiddenPageIndex), "current"));
                }
                currentPagerIndex2++;
            }
            if (lastPagerIndex2 < _LastPageIndex)
            {
                navigateUrl = baseUrl + (lastPagerIndex2 + 1).ToString();
                pagerLinkData2.Add(new PagerLinkData2(">", navigateUrl,lastPagerIndex2+1, true));
            }
            PagerControls2.DataSource = pagerLinkData2;
            PagerControls2.DataBind();
        }
        else
        {
            PagerPanel2.Visible = false;
        }
    }

    public class PagerLinkData2
    {
        private string _Text;
        private int _PageIndex;
        private string _NavigateUrl;
        public int PageIndex { get { return _PageIndex; } }
        private bool _Enabled;
        public string Text { get { return _Text; } }
        public string NavigateUrl { get { return _NavigateUrl; } }
        public bool Enabled { get { return _Enabled; } }
        private string _tagClass;
        public string TagClass { get { return _tagClass; } set { _tagClass = value; } } 
        public PagerLinkData2(string text, string navigateUrl,int pageIndex, bool enabled)
        {
            _Text = text;
            _NavigateUrl = navigateUrl;
            _PageIndex = pageIndex;
            _Enabled = enabled;
        }

        public PagerLinkData2(string text, string navigateUrl, int pageIndex, bool enabled,string tagClass)
        {
            _Text = text;
            _NavigateUrl = navigateUrl;
            _PageIndex = pageIndex;
            _Enabled = enabled;
            _tagClass = tagClass;
        }
    }

    protected void PagerControls_ItemCommand2(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Page")
        {
            InitializePagingVars(false);
            _HiddenPageIndex = AlwaysConvert.ToInt((string)e.CommandArgument);
            if (_HiddenPageIndex < 0) _HiddenPageIndex = 0;
            if (_HiddenPageIndex > _LastPageIndex) _HiddenPageIndex = _LastPageIndex;
            HiddenPageIndex.Value = _HiddenPageIndex.ToString();
        }
    }
    protected void SetPagerIndex2()
    {
        InitializePagingVars(false);
        _HiddenPageIndex = AlwaysConvert.ToInt(Request.QueryString["p"]);
        if (_HiddenPageIndex < 0) _HiddenPageIndex = 0;
        if (_HiddenPageIndex > _LastPageIndex) _HiddenPageIndex = _LastPageIndex;
        HiddenPageIndex.Value = _HiddenPageIndex.ToString();
    }
    #endregion

    protected void Page_PreRender(object sender, EventArgs e)
    {
        //BIND PAGE
        BindPage();
    }

Posted: Mon Mar 24, 2008 4:41 am
by m_plugables
You can use the PageButtonCount property of the GridView to set how many indexed page numbers you want to show