Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataPager and ListView: Custom Datasource

Reply
Thread Tools

DataPager and ListView: Custom Datasource

 
 
Mark Olbert
Guest
Posts: n/a
 
      01-05-2008
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
 
Reply With Quote
 
 
 
 
Toze
Guest
Posts: n/a
 
      01-06-2008
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

"Mark Olbert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      01-07-2008
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/archi...view-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 <aspataPager> 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 ((E-Mail Removed), 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.

 
Reply With Quote
 
Mark Olbert
Guest
Posts: n/a
 
      01-07-2008
Yep, that's what I did. But it seems inelegant.

- Mark

On Sun, 6 Jan 2008 13:50:26 -0000, "Toze" <(E-Mail Removed)> wrote:

>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
>
>"Mark Olbert" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> 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

>

 
Reply With Quote
 
Mark Olbert
Guest
Posts: n/a
 
      01-07-2008
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

On Mon, 07 Jan 2008 08:12:51 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) ("Walter Wang [MSFT]") wrote:

>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/archi...view-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 <aspataPager> 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 ((E-Mail Removed), 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.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      01-09-2008
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/co...ContentID=2220.
Thanks.


Regards,
Walter Wang ((E-Mail Removed), 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Rows with the DataPager and ListView? MU ASP .Net 3 06-20-2013 10:37 PM
custom link format for DataPager's NumericPagerField Adam The Generic ASP .Net 0 05-06-2009 02:15 PM
DataPager and ListView with Randomized Rows? MU ASP .Net 0 10-28-2008 02:09 PM
Custom DataPager. How? shapper ASP .Net 1 02-24-2008 02:42 AM
datapager with custom loading Nedim ASP .Net 1 01-06-2008 01:23 PM



Advertisments