DataPager and ListView: Custom Datasource

Discussion in 'ASP .Net' started by Mark Olbert, Jan 5, 2008.

  1. Mark Olbert

    Mark Olbert Guest

    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
     
    Mark Olbert, Jan 5, 2008
    #1
    1. Advertising

  2. Mark Olbert

    Toze Guest

    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:...
    > 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
     
    Toze, Jan 6, 2008
    #2
    1. Advertising

  3. 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 (, 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.
     
    Walter Wang [MSFT], Jan 7, 2008
    #3
  4. Mark Olbert

    Mark Olbert Guest

    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:...
    >> 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

    >
     
    Mark Olbert, Jan 7, 2008
    #4
  5. Mark Olbert

    Mark Olbert Guest

    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, ("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-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 (, 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.
     
    Mark Olbert, Jan 7, 2008
    #5
  6. 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 (, 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.
     
    Walter Wang [MSFT], Jan 9, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nedim

    datapager with custom loading

    Nedim, Jan 5, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    466
  2. MU
    Replies:
    3
    Views:
    1,254
    thealps
    Jun 20, 2013
  3. MU
    Replies:
    0
    Views:
    385
  4. .nLL
    Replies:
    1
    Views:
    1,042
  5. .
    Replies:
    0
    Views:
    793
Loading...

Share This Page