This is a migrated thread and some comments may be shown as answers.

Datapager not good on page load, good on postback

5 Answers 129 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
vandenbroele
Top achievements
Rank 1
vandenbroele asked on 07 Aug 2011, 08:30 PM
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();
}

5 Answers, 1 is accepted

Sort by
0
vandenbroele
Top achievements
Rank 1
answered on 08 Aug 2011, 01:41 PM
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();
0
vandenbroele
Top achievements
Rank 1
answered on 17 Aug 2011, 05:43 PM
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?
0
Pavlina
Telerik team
answered on 18 Aug 2011, 12:01 PM
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.

0
vandenbroele
Top achievements
Rank 1
answered on 07 Sep 2011, 08:13 AM
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 (?)
0
Iana Tsolova
Telerik team
answered on 12 Sep 2011, 03:34 PM
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.
Tags
DataPager
Asked by
vandenbroele
Top achievements
Rank 1
Answers by
vandenbroele
Top achievements
Rank 1
Pavlina
Telerik team
Iana Tsolova
Telerik team
Share this question
or