LINQ and list paging

I have a page with a listview control and a datapager control. The listviews data source is set programmatically using this code:

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

When I test this page in a browser, it encounters an error: "ListView with identifier" listview1 "must have a data source that either implements ICollection or can swap the data source if AllowPaging is true."

How can I implement swap in this scenario?

thanks

+5
source share
3

listview1.DataSource = bookmarks.ToArray()

.

+18

, OP, - Databind OnPreRender:

    protected void Page_PreRender(object sender, EventArgs e)
    {
        listview1.DataBind();
    }
+2

or perhaps create page properties and change the list of links.

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);

    BindListView();
}
0
source

All Articles