ListView DataPager issue

Federico R 1 Reputation point
2021-06-13T02:23:52.343+00:00

Hello Everyone,

I am using a Listview and a DataPager. The DataPager is configured like this:

        <asp:DataPager ID="DataPager" PageSize="20" class="btn-group btn-group-sm" runat="server">           
            <Fields>                  
                <asp:NextPreviousPagerField  PreviousPageText="<" FirstPageText="<<" ShowPreviousPageButton="true"
                    ShowFirstPageButton="true" ShowNextPageButton="false" ShowLastPageButton="false"
                    ButtonCssClass="btn btn-default" RenderNonBreakingSpacesBetweenControls="false" RenderDisabledButtonsAsLabels="false" />
                <asp:NumericPagerField ButtonType="Link" CurrentPageLabelCssClass="btn btn-default grey-gallery disabled"  RenderNonBreakingSpacesBetweenControls="false"
                    NumericButtonCssClass="btn btn-default" ButtonCount="4" PreviousPageText="..." NextPageText="..." NextPreviousButtonCssClass="btn btn-default" />
                <asp:NextPreviousPagerField NextPageText=">" LastPageText=">>" ShowNextPageButton="true"
                    ShowLastPageButton="true" ShowPreviousPageButton="false" ShowFirstPageButton="false"
                    ButtonCssClass="btn btn-default" RenderNonBreakingSpacesBetweenControls="false" RenderDisabledButtonsAsLabels="false"/>
            </Fields>
        </asp:DataPager>

Everything works fine but this. If i have 15 pages for example... i see blocks of navigation like this

<< < 1 2 3 4 ...> >>
<< < ... 5 6 7 8 ...> >>
<< < ... 9 10 11 12 ...> >>
<< < ... 13 14 15 > >>

When i clic the "..." button after numer 12, that should load last block of page navigation... it does not. But if I hit the ">" it does load. When debugging, i get the same value for e.StartRowIndex when hitting "..." or ">"

        Private Sub Listado_PagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs) Handles Listado.PagePropertiesChanging
            Try
                Paginacion.SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
                DataBindListView()
            Catch ex As Exception
                Throw
            End Try
        End Sub

So it is very weird, starting to think that it is a control bug. Have anyone deal with this?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,455 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yihui Sun-MSFT 801 Reputation points
    2021-06-14T09:57:53.8+00:00

    Hi @Federico R ,

    According to the code you provided, you did not set the PagedControlID. When the PagedControlID is set, the problem you mentioned will not occur.

    1. <asp:DataPager ID="DataPager" PageSize="20" class="btn-group btn-group-sm" runat="server" OnPreRender="Page_Load" PagedControlID="TestListView" >
    2. <asp:ListView ID="TestListView"

    Here is an example, you can refer to it.

    Page:

    xxx.aspx.cs

    Public Partial Class _Default  
        Inherits Page  
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)  
            TestListView.DataSource = testdata()  
            TestListView.DataBind()  
        End Sub  
      
        Public Function testdata() As DataTable  
            Dim table As DataTable = New DataTable()  
            Dim column As DataColumn  
            Dim row As DataRow  
            table.Columns.Add(New DataColumn With {  
                .DataType = Type.[GetType]("System.String"),  
                .ColumnName = "TestId"  
            })  
            table.Columns.Add(New DataColumn With {  
                .DataType = Type.[GetType]("System.String"),  
                .ColumnName = "TestName"  
            })  
      
            For i As Integer = 1 To 500 - 1  
                row = table.NewRow()  
                row("TestId") = i.ToString()  
                row("TestName") = "TestName" & i.ToString()  
                table.Rows.Add(row)  
            Next  
      
            Return table  
        End Function  
    End Class  
    

    Result


    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,
    YihuiSun

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.