Efficient paging with MembershipUser object and pageddatasource

peter liles 556 Reputation points

I am trying to implement efficient paging using LINQ like:

Dim numberOfObjectsPerPage As Integer = ddlPageSize.SelectedValue
Dim queryResultPage = MembershipUserODS.GetMembersCompose(sortexpression, usernametofind, roleid, UsernameToMatch, Me.PageIndex, totalRecords)
queryResultPage.Skip(numberOfObjectsPerPage * Me.PageIndex).Take(numberOfObjectsPerPage)

        pagingSource.DataSource = queryResultPage

The queryResultPage variable returns the total row count and not the subset page size value as expected?

A set of technologies in the .NET Framework for building web applications and XML web services.
3,359 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 27,716 Reputation points Microsoft Vendor

    Hi @peter liles ,

    Return memberList.Skip(startIndex).Take(maxRows).ToList()

    Regarding Skip(1).Take(5), skip the first data and take 5 data from the second.
    What are the values of startIndex and maxRows?
    Maybe you can imitate the following code:

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Lan Huang

  2. peter liles 556 Reputation points

    It is set by a function like below.The membershipuserwrapper is a membershipuser class. i have tried various parameters to test results and it does not effect the output.it still returns the full count ?

    Private Shared memberList As List(Of MembershipUserWrapper)

        <DataObjectMethod(DataObjectMethodType.[Select], False)>
        Public Shared Function GetMembers(ByVal returnAllApprovedUsers As Boolean, ByVal returnAllNotApprovedUsers As Boolean, ByVal usernameToFind As String, ByVal sortExpression As String, ByVal RoleID As String, ByVal UsernameToMatch As String, ByVal startIndex As Integer, ByVal maxRows As Integer, ByVal Optional TotalRows As Integer = 0) As List(Of MembershipUserWrapper)
            memberList = New List(Of MembershipUserWrapper)()

    Return memberList.Skip(maxRows * startIndex ).Take(maxRows).ToList

  3. peter liles 556 Reputation points

    Do i need to use LINQ to obtain a subset of data from my membershipuser constructor or can the data parse be done without the skip and take method.
    by calculating the startrow index and max records returned before adding parameters to constructor?

    0 comments No comments