SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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()
    Dim site As SPSite = Nothing
    Dim web As SPWeb = Nothing
    Dim disposeSPSite As Boolean = False
        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
                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))
                '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

            encodedLiteral_Renamed = New EncodedLiteral()
            encodedLiteral_Renamed.Text = "This webpart is not configured."
        End If
        encodedLiteral_Renamed = New EncodedLiteral()
        encodedLiteral_Renamed.Text = "This webpart is not configured correctly."
        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)

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


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

Browse other questions tagged or ask your own question.