More in this section

telerik pager

3 posts, 1 answered
  1. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    14 Jul 2010
    Link to this post
    Hi Team,

    I was wondering how to use the telerik pager with a repeater in a custom module that I have created. Do you recommend that I use this control or should I implement my own custom paging?

    Thanks,

    George
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Jul 2010
    Link to this post
    Hi G-force,

    It is possible to use it, but the pager is very sensitive. You need to bind it manually to the datasource of the repeater control you have and set items per page, current page etc. Below is  a sample code

      protected int CurrentPage
      {
          get
          {
              object o = this.ViewState["_CurrentPage"];
              if (o == null)
                  return 1;
              else
                  return (int)o;
          }
          set
          {
              this.ViewState["_CurrentPage"] = value;
          }
      }     
     
     
      protected override void CreateChildControls()
      {
     
          Pager pager = MuyCustomContainer.GetControl<Pager>("pager1", false);
          if (pager != null)
             {
                  IList dataSource = null;
                  dataSource = Manager.GetContent();
     
                  int numberOfPages = dataSource.Count / this.ItemsPerPage;
                  if (dataSource.Count % this.ItemsPerPage > 0)
                  {
                      numberOfPages++;
                  }
                  pager.SelectedPageChanged += new EventHandler<EventArgs>(Pager_SelectedPageChanged);
                  pager.PageCount = numberOfPages;
                  pager.SelectedPage = this.CurrentPage;
     
                    
                  this.CustomDataSource = this.Manager.GetLists(this.CurrentPage * this.ItemsPerPage - this.ItemsPerPage, this.ItemsPerPage);
                    
     
      }
     
     
    void Pager_SelectedPageChanged(object sender, EventArgs e)
      {
          this.CurrentPage = ((Pager)sender).SelectedPage;
          this.ChildControlsCreated = false;
      }

    In your control template you should have the pager declared as shown below

    <telerik:Pager ID="pager1" runat="server">
        <LayoutTemplate>
            <asp:Repeater ID="PageRepeaterLinkButton" runat="server">
                <HeaderTemplate>
                    <ol class="sf_pager">
                    <li><asp:LinkButton ID="PreviousPage" runat="server" Text="PreviousPage"></asp:LinkButton></li>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:LinkButton ID="SingleItem" runat="server" />
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    <li><asp:LinkButton ID="NextPage" runat="server" Text="NextPage"></asp:LinkButton></li>
                    </ol>
                </FooterTemplate>
            </asp:Repeater>
            <asp:Repeater ID="PageRepeaterHyperLink" runat="server">
                <HeaderTemplate>
                    <ol class="sf_pager">
                    <li><asp:HyperLink ID="PreviousPage" runat="server" Text="PreviousPage"></asp:HyperLink></li>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="SingleItem" runat="server" />
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    <li><asp:HyperLink ID="NextPage" runat="server" Text="NextPage"></asp:HyperLink></li>
                    </ol>
                </FooterTemplate>
            </asp:Repeater>
        </LayoutTemplate>
    </telerik:Pager>


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    14 Jul 2010
    Link to this post
    Appreciate it Ivan ... I will try it ...
Register for webinar
3 posts, 1 answered