DataPager and ListView: Custom Datasource

M

Mark Olbert

How do I get the DataPager and ListView to play nice together when I use a custom datasource?

In my webpage, I use linq to pull data from a SqlServer database and assign the resulting IEnumerable<> to the ListView's Datasource
property. This all works fine to display the first 3 items (the DataPager is set to display three items at a time), but when I click
on the next page in the DataPager...nothing happens. There's a roundtrip to the server, but the page doesn't update to reflect new
records.

I suspect there's some dependency between the DataPager control and the Datasource. No doubt this would all work if I used an
SqlDataSource. But I don't want to do that. The website is mostly a means for me to learn how to use linq...and after only a day of
work, there is no way I would willingly go back to the pre-linq approaches :). Besides, if Microsoft includes powerful new data
technology like linq in the Framework, there ought to be a way to have it work with at least the new data-bound controls (e.g., the
ListView).

- Mark
 
T

Toze

if you want to control all the process you need to create a custom paging
control

with server side events its simple to control paging...
a simple control with next previous buttons that trigguers events when
clicked. And in the page that olds the grid capture the events and change
the datasource with the new data
 
W

Walter Wang [MSFT]

Hi Mark,

Please see following example:

#The asp:ListView control (Part 1 - Building a Product Listing Page with
Clean CSS UI) - ScottGu's Blog
http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-p
art-1-building-a-product-listing-page-with-clean-css-ui.aspx
<blockquote>
One of the other new controls in ASP.NET 3.5 is the <asp:DataPager> control
- which makes data paging scenarios with the ListView control pretty easy.
You can drop it anywhere you want on a page, and set its "PagedControlID"
property to point at the ListView, and its "PageSize" property to indicate
how many items in the ListView you want displayed at a time
</blockquote>


It has an example Products_LinqDataSource.aspx that demonstrates how to use
ListView, DataPager and LinqDataSource together.

(You need to change "itemContainer" to "itemPlaceholder" in the ListView
markup, the example was written before .NET 3.0 RTMed).

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Olbert

Walter,

The example doesn't answer my question because it depends on using the LinqDataSource, which is fine when you just want to pull data
from a single table but doesn't work for more complex queries. As an aside, it would be nice to know if there are plans to extend
the LinqDataSource control so that it acts more like the SqlDataSource control (i.e., supports more complex SELECT queries).

Basically, what I'm doing (in the code behind) is this:

1) Retrieve data from database using LINQ
2) Assign retrieved results to ListView.Datasource. The ListView has an associated DataPager control.
3) Databind() ListView

Paging does not work in this situation.

I think paging requires the use of a LinqDataSource (or SqlDataSource) control to work. I'd like to confirm that.

- Mark
 
W

Walter Wang [MSFT]

Hi Mark,

I think in this case, the custom data source must support paging. The
DataPager needs this to support paging. In LINQ for SQL, I believe you can
use Take() and Skip() to implement paging support.

For feature request about LinqDataSource, please feel free to submit at
http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220.
Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top