views:

1131

answers:

3

Hi,

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
listview1.DataBind()

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?

Thanks

+3  A: 

Try

listview1.DataSource = bookmarks.ToArray()

I had the same problem this week.

KClough
Thankyou so much! Very quick response. Cannot believe it was something that simple.
One minor problem, i have to click the page numbers twice before it goes to the next page or previous page. Any idea how to solve this? Thanks.
Better yet use `ToArray()` - it's slightly more lightweight if you don't actually need full functionality of `List` (such as adding new items) - which you do not here; and arrays implement `ICollection` (and `IList`) otherwise.
Pavel Minaev
Good call Pavel, thanks!
KClough
briggins5, sounds like a problem with the code that keeps track of the current page/binds data, best suited for another post if you're still stuck
KClough
Thanks for the help guys. I'll ask a new question if i can't fix it myself.
A: 

Thank you. I got hellped by this answer.

Reinaldo Sanchez
A: 

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)
    {
        listview1.DataBind();
    }
CJM