Linq to Sql vs LinqDataSource and ListView paging problem

Linq to Sql vs LinqDataSource and ListView paging problem

Postby mainship » Fri 27 Mar 2009 15:21

I have a page with a number of drop down boxes and check boxes that the user can use to define a search against the database. There is also a ListView control that is supposed to display the results of the search. The ListView uses a DataPager defined in the ListView's LayoutTemplate to handle paging. Finally, I have a dynamic query built on the user's selections.

After much trial and error, numerous Google searches, and several posts, I finally got the dynamic query to work. It works in the LinqDataSource selecting event, and in the search button click event in that it returns the right records. But when I click the search button, I lose all paging ability.

ListView1.DataSource = InmProfile.ToList()
ListView1.DataBind()

is apparently not the same thing as a linqdatasource. How do I handle this? Can I somehow force the LinqDataSource selecting event to fire instead of or in addition to the search button click event, and leave the dynamic query in the LinqDataSource selecting event? Or do I assign the search button click event's query results to the ListView in a different way?

Diane
mainship
 
Posts: 6
Joined: Fri 27 Mar 2009 01:38

Postby AndreyR » Tue 31 Mar 2009 11:46

You can use Skip() and Take() methods to implement paging in your LINQ query.
As an alternative, you can add one more LinqDataSource with dynamic query in its Selecting event and set its query in the button_click event.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby mainship » Tue 31 Mar 2009 12:32

I like your alternative. But how do I "set its query in the button_click event"? This sounds like what I'm looking for but I'm drawing a blank on how to do it.

Diane
mainship
 
Posts: 6
Joined: Fri 27 Mar 2009 01:38

Postby AndreyR » Wed 01 Apr 2009 11:07

You can send a small test project to support * devart * com with subject "LINQ: Paging trouble", I'll look into it.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16


Return to LinqConnect (LINQ to SQL support)