DataPager and ListView: Custom Datasource
DataPager and ListView: Custom Datasource
am 05.01.2008 03:12:41 von 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
Re: DataPager and ListView: Custom Datasource
am 06.01.2008 14:50:26 von 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
"Mark Olbert" wrote in message
news:0iptn3ds8jel45tqluf2vdffq1d4pttg90@4ax.com...
> 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
RE: DataPager and ListView: Custom Datasource
am 07.01.2008 09:12:51 von wawang
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-li stview-control-p
art-1-building-a-product-listing-page-with-clean-css-ui.aspx
One of the other new controls in ASP.NET 3.5 is the 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
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 (wawang@online.microsoft.com, 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.
Re: DataPager and ListView: Custom Datasource
am 07.01.2008 18:47:41 von Mark Olbert
Yep, that's what I did. But it seems inelegant.
- Mark
On Sun, 6 Jan 2008 13:50:26 -0000, "Toze" 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" wrote in message
>news:0iptn3ds8jel45tqluf2vdffq1d4pttg90@4ax.com...
>> 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
>
Re: DataPager and ListView: Custom Datasource
am 07.01.2008 18:54:39 von 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
On Mon, 07 Jan 2008 08:12:51 GMT, wawang@online.microsoft.com ("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/archive/2007/08/10/the-asp-l istview-control-p
>art-1-building-a-product-listing-page-with-clean-css-ui.asp x
>
>One of the other new controls in ASP.NET 3.5 is the 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
>
>
>
>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 (wawang@online.microsoft.com, 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.
Re: DataPager and ListView: Custom Datasource
am 09.01.2008 03:02:50 von wawang
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?Conte ntID=2220.
Thanks.
Regards,
Walter Wang (wawang@online.microsoft.com, 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.