Datapager not good on page load, good on postback

6 posts, 0 answers
  1. vandenbroele
    vandenbroele avatar
    17 posts
    Member since:
    Sep 2007

    Posted 07 Aug 2011 Link to this post

    Hello

    I'm not getting this right. I want to display a feed from youtube. All the data is comming in fine. The youtube feeds will return chuncks of video's with a startindex ... so I have to use the PageIndexChanged to alter the paging.

    Alas, it does only work correct afer I click one of the pages. This means that on original page load, it will still take the default pagesize of 10. Any help would be wonderful.

    Btw, this is a radListview with radDatapager.


    protected override void LoadPage()
    {
        // make youtube channel
        channel = new YouTubeChannel(PMSettings.GetPortalSetting("channel"),
                                     PMSettings.GetPortalSetting("devkey"),
                                     PMSettings.GetModuleSetting("pagesize", 6));
     
        if (!IsPostBack)
        {
            // request video feed
            feed = channel.Search("", 1);
     
            // configure list view
            ListViewVideos.PageSize = feed.PageSize;
            ListViewVideos.VirtualItemCount = feed.TotalResults;
     
            // data bind
            ListViewVideos.DataSource = feed.Entries;
            ListViewVideos.DataBind();
        }
    }
     
    protected void ListViewVideos_PageIndexChanged(object sender, Telerik.Web.UI.RadListViewPageChangedEventArgs e)
    {
        // request video feed
        feed = channel.Search("", e.NewPageIndex + 1);
     
        // configure list view
        ListViewVideos.PageSize = feed.PageSize;
        ListViewVideos.VirtualItemCount = feed.TotalResults;
     
        // data bind
        ListViewVideos.DataSource = feed.Entries;
        ListViewVideos.DataBind();
    }

  2. vandenbroele
    vandenbroele avatar
    17 posts
    Member since:
    Sep 2007

    Posted 08 Aug 2011 Link to this post

    I figured it "works" if I run the following code twice in the page load:

    ListViewVideos.PageSize = feed.PageSize;
    ListViewVideos.VirtualItemCount = feed.TotalResults;
    ListViewVideos.DataSource = feed.Entries;
    ListViewVideos.DataBind();
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. vandenbroele
    vandenbroele avatar
    17 posts
    Member since:
    Sep 2007

    Posted 17 Aug 2011 Link to this post

    I am still struggling with this problem.

    Like this, it works too:

    protected void Page_Load()
            {
                if (!IsPostBack)
                {
                    MyList.DataBind();
                    MyList.VirtualItemCount = MyDataWrapper.Items;
                    MyList.PageSize = MyDataWrapper.Pagesize;
                    MyList.DataSource = MyDataWrapper.Entries;
                }
            }

    The databinding happens before the source assignment.
    This makes no sense, but like this it works ...

    Any help?
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 18 Aug 2011 Link to this post

    Hello Vandenbroele,

    Please note that in order to use paging functionality you should use either advanced databinding or declarative databinding.

    All the best,
    Pavlina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. vandenbroele
    vandenbroele avatar
    17 posts
    Member since:
    Sep 2007

    Posted 07 Sep 2011 Link to this post

    Settings the pagesize on the listview has no direct effect, whether it is done in a pageload event or a listview-OnNeedDataSource event.
    Even when setting the pagesize in the ascx control as a parameter, this did only work AFTER changing the pagenumber... So, when the page loads for the first time, the list takes its default value of 10 per page.

    I figured setting the pagesize parameter directly on the datapager in the ascx, did work immediately.
    I tried accessing the datapager in the OnNeedDataSource but discovered I could only access it in the layoutcreated event.

    Right now, this works very well, but I'm still wondering why the pagesize property on a listview seems to be bugged (?)
  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 12 Sep 2011 Link to this post

    Hi Vandenbroele,

    When using the RadDataPager for paging RadListView, the page size is controlled by the RadDataPager. That is why you should get the value for the PageSize from it. To overcome the issue you are facing, you can try setting the same value for the RadDataPager and the RadListView initially, in he declaration. Then when the page size is changed throug the RadDataPager, change the new PageSize for the RadListView as well.

    Let me know if this approach works.

    All the best,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017