+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / External Temlplate Repeater

External Temlplate Repeater

4 posts, 0 answered
  1. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    14 Dec 2010
    Link to this post
    Hi,
    I am using an external template to show the News items using repeater. I want to add a paging functionaly in this repeater.
    Any help?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Dec 2010
    Link to this post
    Hi Asif,

    You can use RadDataPager with a control that implements IPageableItemContainer or IRadPageableItemContainer interface

    For the Repeater control you can reuse our Pager.

    sample

    1. Implement properties that will allow you to set items per page, number of pages etc

    sample

    /// <summary>
    /// Defines wheter it is possible to page through posts or all posts should be
    /// displayed on one page.
    /// </summary>
    [Category("Paging")]
    public bool AllowPaging
    {
        get
        {
            object obj = this.ViewState["AllowPaging"];
            if (obj != null)
                return (bool)obj;
            return true;
        }
        set
        {
            this.ViewState["AllowPaging"] = value;
        }
    }
     
    /// <summary>
    /// Defines query string name used to set the current shown page when paging is enabled
    /// </summary>
    [Category("Paging"),
    DefaultValue("Page")]
    public string PageKey
    {
        get
        {
            object obj = this.ViewState["PageKey"];
            if (obj != null)
                return (string)obj;
            return "Page";
        }
        set
        {
            this.ViewState["PageKey"] = value;
        }
    }
     
    /// <summary>
    /// If paging is allowed, this property specifies how many posts per page should
    /// be displayed.
    /// </summary>
    [Category("Paging")]
    public int PostsPerPage
    {
        get
        {
            object obj = this.ViewState["PostsPerPage"];
            if (obj != null)
                return (int)obj;
            return 10;
        }
        set
        {
            this.ViewState["PostsPerPage"] = value;
        }
    }
     
    /// <summary>
    /// If paging is allowed, this property specifies what kind of pager should be
    /// displayed.
    /// </summary>
    [Category("Paging")]
    public PagerMode PagingMode
    {
        get
        {
            object obj = this.ViewState["PagingMode"];
            if (obj != null)
                return (PagerMode)obj;
            return PagerMode.Both;
        }
        set
        {
            this.ViewState["PagingMode"] = value;
        }
    }
     
    /// <summary>
    /// Gets or sets the current result page
    /// </summary>
    protected int CurrentPage
    {
        get
        {
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 1;
            else
                return (int)o;
        }
        set
        {
            this.ViewState["_CurrentPage"] = value;
        }
    }


    2. Rebind the control depending on the current page

    sample

    // check if query string is supplied to select the current page
    if(!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[PageKey]))
         {
             this.CurrentPage = Convert.ToInt32(
             HttpContext.Current.Request.QueryString[PageKey]);
         }
     
               ...
     
     int totalItems;
     int startIndex = (this.CurrentPage - 1) * this.PostsPerPage;
     
     
     
    int numberOfPages = (this.PostsPerPage == 0) ? 1 : (int)Math.Ceiling((double)totalItems / (double)this.PostsPerPage);
     
    if (numberOfPages == 0 && totalItems > 0)
    numberOfPages = 1;
     
    if (this.AllowPaging)
        {
            // initialize pager
         this.Pager1.SelectedPageChanged += new EventHandler<EventArgs>(Pager_SelectedPageChanged);
         this.Pager1.PageCount = numberOfPages;
         this.Pager1.SelectedPage = this.CurrentPage;
        }
     
     
       void Pager_SelectedPageChanged(object sender, EventArgs e)
         {
                this.CurrentPage = ((Pager)sender).SelectedPage;
                this.ChildControlsCreated = false;
         }
     
     
     
     ....
              ....
      #region Container
     
            /// <summary>
            /// Default Container for the CustomNewsControl 
            /// </summary>
            protected class Container : GenericContainer<CustomNewsControl >
            {
                #region Construction
                public Container ( CustomNewsControl owner )
                    : base ( owner )
                {
                }
                #endregion
     
     
                 
                private Pager pager1;
     
                public Pager Pager1
                {
                    get
                    {
                        if (this.pager1 == null)
                            this.pager1 = base.FindRequiredControl<Pager>("pager1");
                        return this.pager1;
                    }
                }
            }


    All the best,
    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
  3. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    15 Dec 2010
    Link to this post
    Hi,
    Can you please eloborate the second part to bind the controller. I am not really sure where to place the code and how to bind it with my repeater control? the first chunk of the code which is a property I have put it in my page code behind but note sure about the second chunk of code. Hard to understand. Can you please make it really use full for me?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Dec 2010
    Link to this post
    Hi Asif,

    You should put the code in the same class where you bind the repeater. You  have to subscribe for ItemCommand and calculate the paging size so you will bind the Repeater to subset of the data source. You can use GetContent(int from, int max)  


    All the best,
    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
Register for webinar
4 posts, 0 answered