Custom pagin template

Member since: 2008
 

Hi,

 I have a pagelist with paging turned on. I want to edit the rendered paging links. I know I can change the text for the last and first page link, but I want to get rid of the page numbers and replace with my own custom text. 

Does anyone know how to do this? As the paging footer/header template only adds to what's already there, not display in its place.

 

Thanks 

#19742 May 01, 2008 12:12
  • Member since: 2006
     

    Hi Kevin.

     I don`t think that is possible. But you can make your own paging control and that to the PageList like this PageList.PagingControl = customPager();

    Just use Reflector on the EPiServer.dll and you will find the PagingControl under EPiServer.Web.WebControls.PagingControl. You only need to override the CreatePagingItems(PageDataCollection pages).

    I have made my own pagingcontrol like this. Works like a charm :)

     BR,

    Tore 

    #19767 May 03, 2008 18:00
  • Member since: 2008
     

    Hi, thanks for the tip, do you have a sample code you can post for me at all?

     

    thanks 

    #19798 May 06, 2008 13:38
  • Member since: 2006
     

    Hi Kevin.

    I have made a sample for you here. In the for loop, the page numbers are written out. You could either send you own text to AddSelectedPagingLink and the AddUnselectedPagingLink, or you can override them with you own code. Hope this helps you on your way :)

    <code>

    using System;
    using EPiServer.Core;
    using EPiServer.Web.WebControls;

    namespace EPiServerSample.Templates.WebControls
    {
    public class CustomEPiPager : PagingControl
    {
    // Fields
    private int _linkCounter;

    private string Translate(string text)
    {
    return LanguageManager.Instance.Translate("/webcontrols/paging/" + text);
    }

    public override void CreatePagingItems(PageDataCollection pages)
    {
    int pagingIndex = CurrentPagingItemCount - 1;
    bool visible = CurrentPagingItemIndex > 0;
    bool flag2 = CurrentPagingItemIndex < pagingIndex;
    if ((pagingIndex != 0) || !AutoPaging)
    {
    _linkCounter = 0;
    if (FirstPagingItemText.Length > 0)
    {
    AddUnselectedPagingLink(0, FirstPagingItemText, Translate("firstpage"), visible);
    AddLinkSpacing(visible);
    }
    if (PrevPagingItemText.Length > 0)
    {
    AddUnselectedPagingLink(CurrentPagingItemIndex - 1, PrevPagingItemText, Translate("prevpage"), visible);
    AddLinkSpacing(visible);
    }
    for (int i = 0; i <= pagingIndex; i++)
    {
    if (i == CurrentPagingItemIndex)
    {
    AddSelectedPagingLink(i, Convert.ToString((int)(i + 1)), Translate("currentpage"));
    }
    else
    {
    AddUnselectedPagingLink(i, Convert.ToString((int)(i + 1)), string.Format(Translate("pagenumber"), i + 1), true);
    }
    if (i < pagingIndex)
    {
    AddLinkSpacing();
    }
    }
    if (NextPagingItemText.Length > 0)
    {
    AddLinkSpacing(flag2);
    AddUnselectedPagingLink(CurrentPagingItemIndex + 1, NextPagingItemText, Translate("nextpage"), flag2);
    }
    if (LastPagingItemText.Length > 0)
    {
    AddLinkSpacing(flag2);
    AddUnselectedPagingLink(pagingIndex, LastPagingItemText, Translate("lastpage"), flag2);
    }
    }
    }
    }
    }

    </code> 

     

    Here is AddSelectedPageLink and AddUnselectedPageLink if you need them. Just include them in your CustomEPiPager class and override them.  

    <code>

    protected virtual LinkButton AddSelectedPagingLink(int pagingIndex, string text, string altText)
    {
    LinkButton child = this.CreatePagingLink(pagingIndex, text, altText);
    child.CssClass = CssClassSelected;
    Controls.Add(child);
    return child;
    }

    protected virtual LinkButton AddUnselectedPagingLink(int pagingIndex, string text, string altText, bool visible)
    {
    LinkButton child = this.CreatePagingLink(pagingIndex, text, altText);
    child.CssClass = CssClassUnselected;
    child.Visible = visible;
    Controls.Add(child);
    return child;
    }

    </code> 

    #19836 May 08, 2008 8:36
  • Member since: 2008
     

    Hi,

    Thanks a lot for the code sample, it works great!

    Just one small issue. When the next page button is pressed, the page data doesn't actually move forward, it just triggers a postback and the data stays the same. Then on the 2nd press, it moves forward as expected.

    Is this a problem you've come across before?

    Also, at which event of the page is it best to assign the custom paging class to the pagelist? I currently do it on pageinit, is this correct?

    Thanks 

    #19872 May 12, 2008 11:20
  • This message was deleted by kevinpang at May 12, 2008 11:22.
  •  

    I've got the same problem
    I need to click 2 times to move to the next 10 pages in my pagelist

     Any soloutions?

     

    /jesper

    #20277 May 26, 2008 8:34
  • Member since: 2006
     
    Hi Kevin And Jesper.

    I tested it out and got the same problem. I am not sure why this propblem accours, but you could try overriding more of the source(EPiServer.Web.WebControls.PagingControl).

    I copied the whole code(EPiServer.Web.WebControls.PagingControl) from Reflector and got it to work. You should however just override the things you need. But this a way to start :)

    BR,

    Tore

    #20283 May 26, 2008 10:23
  •  

    Hmm ok
    I've copied all code from pagingControl  but get this error

    'EPiServer.Web.WebControls.PageListData' does not contain a definition for 'CurrentPagingItemIndex' 

     

    /jesper

    #20288 May 26, 2008 11:50
  • Member since: 2006
     

    Which version of EPiServer are you using? Try leaving out the CurrentPagingItemIndex property.

    <code>

      public virtual int CurrentPagingItemIndex
    {
    get
    {
    if (this._source == null)
    {
    return 0;
    }
    return this._source.CurrentPagingItemIndex;
    }
    set
    {
    this._source.CurrentPagingItemIndex = value;
    }
    }

    </code> 

     

    Tore 

    #20290 May 26, 2008 12:13
  •  

    I need CurrentPagingItemIndex to when I call the PagingItemChanged

    I think my problem is the 'Source'

    I set the pagingControl like this

    PagingControl customPaging = new epiPager();
    NewsPageList.PagingControl = customPaging;

    Should I define the the dataSource for customPaging?

    /jesper 

    #20296 May 26, 2008 13:18
First   1 2 3   Last