LINQ and paging with a listview

LINQ and paging with a listview

I have a page with a listview control and a datapager control. The listviews datasource is set programatically using this code:

Dim dal as new dalDataContext
Dim bookmarks = From data In dal.getData(userid)
listview1.DataSource = bookmarks

When i test this page in a browser it comes up with the error: ‘ListView with id ‘listview1′ must have a data source that either implements ICollection or can perform data source paging if AllowPaging is true.’
How can i implement paging in this scenario?


Solution 1:


listview1.DataSource = bookmarks.ToArray()

I had the same problem this week.

Solution 2:

An answer to the click-twice problem that the OP subsequently encountered – move the Databind to the OnPreRender event handler:

    protected void Page_PreRender(object sender, EventArgs e)

Solution 3:

or maybe create a page properties changing and bindlistview there.

protected void lv_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    //set current page startindex, max rows and rebind to false
    DataPager dp = lvNews.FindControl("lvDataPager1") as DataPager;
    dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);