Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list web part to show any list on any site or site collection, it's working great except for the paging. when I click on the next page arrow, it stays on the same page. It seems that the position is not working. I've double checked the paginfo string returned when I click and it's OK. So if someone have any clues...

Here's part of the code:

 Protected Overrides Sub CreateChildControls()
    MyBase.CreateChildControls()
    Dim site As SPSite = Nothing
    Dim web As SPWeb = Nothing
    Dim disposeSPSite As Boolean = False
    Try
        If Me.SourceList <> String.Empty AndAlso Me.SourceList <> String.Empty Then
            viewByQuery = New ListViewByQuery()
            If Me.SiteUrl IsNot Nothing AndAlso Me.SiteUrl <> String.Empty Then
                site = New SPSite(Me.SiteUrl)
                disposeSPSite = True
            Else
                site = SPContext.Current.Site
            End If
            web = site.OpenWeb()
            Dim sourceList As SPList = web.Lists(Me.SourceList)
            viewByQuery.List = sourceList
            Dim query As SPQuery = Nothing
            If CheckIfViewExists(viewByQuery.List) Then
                'use the view specified in webpart property  
                query = New SPQuery(viewByQuery.List.Views(Me.ViewName))
            Else
                'use default view to initialized  
                query = New SPQuery(viewByQuery.List.DefaultView)
            End If

            query.RowLimit = 20
            Dim pos As String = GetPageInfo()
            Dim position As New SPListItemCollectionPosition(pos)
            query.ListItemCollectionPosition = position

            viewByQuery.Query = query
            viewByQuery.DisableFilter = Me.DisableFilter
            viewByQuery.DisableSort = Me.DisableSort

            Me.Controls.Add(viewByQuery)
        Else
            encodedLiteral_Renamed = New EncodedLiteral()
            encodedLiteral_Renamed.Text = "This webpart is not configured."
            Me.Controls.Add(encodedLiteral_Renamed)
        End If
    Catch
        encodedLiteral_Renamed = New EncodedLiteral()
        encodedLiteral_Renamed.Text = "This webpart is not configured correctly."
        Me.Controls.Add(encodedLiteral_Renamed)
    Finally
        If disposeSPSite Then
            CType(site, IDisposable).Dispose()
            CType(web, IDisposable).Dispose()
        End If
    End Try

End Sub
Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)

    EnsureChildControls()
    RenderChildren(writer)
End Sub

Region "helper methods "

Private Function CheckIfViewExists(ByVal list As SPList) As Boolean
    Dim ret As Boolean = False

    For Each view As SPView In list.Views
        If view.Title.ToLower() = Me.ViewName.ToLower() Then
            ret = True
        End If
    Next view
    Return ret
End Function

Private Function GetPageInfo() As String

    If (Not String.IsNullOrEmpty(Me.Context.Request.QueryString("Paged"))) AndAlso (Not String.IsNullOrEmpty(Me.Context.Request.QueryString("View"))) Then

        Dim queryString As String = String.Empty

        For Each key As String In Me.Context.Request.QueryString.Keys

            If key.ToLower() <> "view" Then

                queryString &= key & "=" & Me.Context.Request.QueryString(key) & "&"
            End If

        Next key


        Return Left(queryString, Len(queryString) - 1)

    End If

    Return ""

End Function

End Region

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.