locked
ListView1_PagePropertiesChanged issue RRS feed

  • Question

  • User-1578974752 posted

    I have a List view with pager.

     Once the user click 2 (page2) in listview ,how can I make page 1 (That is only 1 showing below the list view ) to invisible and when they click  3 then 1 and 2 will become invisible so that user can not return to page 1 and 2 ,once they reach page 3.  Pageview properties of list view page is not familiar...How can I call the page number in Protected Sub ListView1_PagePropertiesChanged(sender As Object, e As EventArgs)

    Appreciate the help

    Protected Sub ListView1_PagePropertiesChanged(sender As Object, e As EventArgs)

    Button1.Visible = True

      End Sub

    Tuesday, October 23, 2018 9:28 AM

Answers

  • User-893317190 posted

    Hi shsu,

    I am sorry, I haven't seen your datapager is outside the listview,

    Please change your code 

    Dim dtpgr As DataPager = CType(ListView1.FindControl("DataPager1"), DataPager) 'get the datapage

    To

    Dim dtpgr As DataPager =dtpgr

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 24, 2018 6:29 AM

All replies

  • User-893317190 posted

    Hi shsu,

    If you open F12 , you will find  the element which represents current page is a span and other  page numbers is represented as  <a> link .

    So you could use js to finish your requirement.

    Below is  the datapager  when the page number is three.

    <span id="ListView1_DataPager1">
    <a class="numeric_button" href="javascript:__doPostBack('ListView1$DataPager1$ctl00$ctl00','')">1</a>
    &nbsp
    ;<a class="numeric_button" href="javascript:__doPostBack('ListView1$DataPager1$ctl00$ctl01','')">2</a>&nbsp;
    
    <span class="current_page">3</span>&nbsp;
    </span>

    And my js .  DataPager1 is the id of your datapager.

    $(function () {
    
                $("table [id*=DataPager1]  span").prevAll().hide()  // make all the a link hide
    
                })

    The result.

    Best regards,

    Ackerly Xu

    Wednesday, October 24, 2018 2:59 AM
  • User-1578974752 posted

    I didn't use javascript in my code.can provide how to incorporate in my code. Thanks

    Wednesday, October 24, 2018 3:23 AM
  • User-893317190 posted

    Hi shsu

    If you want to use code behind. You could  use listview's   OnPagePropertiesChanging and OnDataBound event.

    Below is my code.

    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" ItemPlaceholderID="itemPlaceHolder" DataKeyNames="id"  OnPagePropertiesChanging="ListView1_PagePropertiesChanging"
                OnDataBound="ListView1_DataBound"
                >

    Code behind.

     Private pageNumber As Int32    'record the currentPage
        Protected Sub ListView1_PagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs)
            pageNumber = e.StartRowIndex / e.MaximumRows
        End Sub
    
        Protected Sub ListView1_DataBound(sender As Object, e As EventArgs)   
            Dim pager As DataPager = CType(ListView1.FindControl("DataPager1"), DataPager) 'get the datapager
            For index = 0 To pageNumber - 1  'make previous page numbers invisiable
                pager.Controls(0).Controls(index * 2).Visible = False
            Next
    
        End Sub

    Best regards,

    Ackerly Xu

    Wednesday, October 24, 2018 4:37 AM
  • User-1578974752 posted

    Protected Sub ListView1_PagePropertiesChanged(sender As Object, e As EventArgs)

    'Dim list As ListView = ListView1

    'Dim btn As Button = CType(list.FindControl("Button1"), Button)

    Button1.Visible = True

    Dim pageNumber As Integer = ((dtpgr.StartRowIndex) / dtpgr.MaximumRows) + 1

    k = pageNumber

    ' Label1.Text = ""

    End Sub

    Protected Sub ListView1_DataBound(sender As Object, e As EventArgs)

    Dim dtpgr As DataPager = CType(ListView1.FindControl("DataPager1"), DataPager) 'get the datapager

    For index = 0 To k - 1 'make previous page numbers invisiable

    dtpgr.Controls(0).Controls(index * 2).Visible = False

    Next

    End Sub

    error is showing for the above code.

    Wednesday, October 24, 2018 5:54 AM
  • User-893317190 posted

    Hi shsu,

    I write

     pageNumber = e.StartRowIndex / e.MaximumRows

    Your  code is

    Dim pageNumber As Integer = ((dtpgr.StartRowIndex) / dtpgr.MaximumRows) + 1

    Please remove the code I have hightlighted , it should be well.

    Best regards,

    Ackerly Xu

    Wednesday, October 24, 2018 6:03 AM
  • User-1578974752 posted

    Done as below as your code .error is:

    System.NullReferenceException: 'Object reference not set to an instance of an object. dtpgr is my pager name. Showing pager is Nothing.When I click page 2,this happened.When I click page 2,page 1 must become invisble.After saving Page 2 when I click page 3 both page 1 ang page 2 must become invisible.

    Private pageNumber As Int32 'record the currentPage

    Protected Sub ListView1_PagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs)

    Button1.Visible = True

    pageNumber = e.StartRowIndex / e.MaximumRows

    End Sub

    Protected Sub ListView1_DataBound(sender As Object, e As EventArgs)

    Dim pager As DataPager = CType(ListView1.FindControl("dtpgr"), DataPager) 'get the datapager

    For index = 0 To pageNumber - 1 'make previous page numbers invisiable

    pager.Controls(0).Controls(index * 2).Visible = False

    Next

    End Sub

    Wednesday, October 24, 2018 6:10 AM
  • User-893317190 posted

    Hi shsu,

    I find you code 

    <asp:Datapager ID="dtpgr" runat="server" pagedcontrolid="ListView1" Pagesize="5">

    and , my code is to find tghe datapager , so you should change it to the id of your datapager.

    Dim dtpgr As DataPager = CType(ListView1.FindControl("DataPager1"), DataPager) 'get the datapager

    Please change it to

    Dim dtpgr As DataPager = CType(ListView1.FindControl("dtpgr"), DataPager) 'get the datapager

    Best regards,

    Ackerly Xu

    Wednesday, October 24, 2018 6:18 AM
  • User-893317190 posted

    Hi shsu,

    I am sorry, I haven't seen your datapager is outside the listview,

    Please change your code 

    Dim dtpgr As DataPager = CType(ListView1.FindControl("DataPager1"), DataPager) 'get the datapage

    To

    Dim dtpgr As DataPager =dtpgr

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 24, 2018 6:29 AM
  • User-1578974752 posted

    Tahnks Ackerly,It is working

    Wednesday, October 24, 2018 6:41 AM