Paging by example - help - still no luck....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tmuld

    Paging by example - help - still no luck....

    Hello,

    I was looking at the example provided on:
    eSports News, Results, upcoming Matches & live Matches. Learn tricks and guides in the esports space. ✅ We cover CS:GO, Dota 2, LOL, Overwatch & PUBG. 

    for paging.

    I am using Visual Studio 2003 - Microsoft Development Environment 2003

    For paging the page url mentions setting properties to be set as:

    AllowPaging="Tr ue"
    PageSize="15"
    OnPageIndexChan ged="dgPopularF AQs_Paged">

    Ok. I am looking at my datagrid in the design view - there is a Allow
    Paging, PageSize - but no OnPageIndexChan ged!!

    I went to the code behine - at the top selected my datagrid in the top
    left drop down menu, and could not find OnPageIndexChan ged in the
    declarations menu. There is a 'PageIndexChang ed' changed - is that it?

    Well, I put this code in that area (using a Dataset called ds):


    Private Sub dg_PageIndexCha nged(ByVal source As Object, ByVal e As
    System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
    dg.PageIndexCha nged
    dg.CurrentPageI ndex = e.NewPageIndex
    dg.DataBind()
    End Sub

    The paging numbers show up on the grid, but when I hit any of the
    numbers - the same screen shows up - 10 records, it does not advance
    (set to 10 in the property builder). It never advances. In my page
    load I have this:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not Page.IsPostBack Then

    dgDataBind()
    End If
    End Sub

    Any help?

    Thanks,

    Tmuld

  • Cor Ligthert

    #2
    Re: Paging by example - help - still no luck....

    Tmuld,

    Why don't you just use the samples on MSDN for paging a datagrid, they are
    in my opinion very well.

    One of them


    I hope this helps,

    Cor


    Comment

    • Tmuld

      #3
      Re: Paging by example - help - still no luck....

      Thanks - it does work very well!

      I still have some issues. I used the MSDN code and it sort of works.
      Now the paging works, but when I hit the number - it does not show my
      records until I hit the search button again. I thought it would go to
      the next records automatically. Not sure why? Do I need to do some
      sort of refresh at the button level?

      [Plus I also do not understand this line:

      dsQuery = CType(Session(" dataset"), DataSet1). I already have a
      dataset defined at design time - what does this do? ]

      Here is my code:
      - my dataset is called 'ds'

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
      System.EventArg s) Handles MyBase.Load
      'Put user code to initialize the page here
      With dg
      .AllowPaging = True
      .PagerStyle.Mod e = PagerMode.Numer icPages
      .PageSize = 5
      .PagerStyle.Pag eButtonCount = 5
      End With
      If IsPostBack Then
      ds = CType(Session(" dataset"), DataSet1)
      Else
      daQuery.Fill(ds )
      Session("datase t") = ds
      DataBind()
      End If
      End Sub

      The button code->filters out data with a dataview. So after the page
      button is pressed - one gets a blank screen untill the button is
      pressed again - then it moves to the next results.

      Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
      System.EventArg s) Handles btn.Click
      Dim Count As Integer

      Dim dv As DataView = ds.Tables("DB") .DefaultView
      dv.RowFilter = "Title like '%" & txt.Text & "%' OR Address like
      '%" & txt.Text & "%'"
      Count = dv.Count
      dg.DataSource = dv
      dg.DataBind()
      lblCount.Text = Count

      End Sub

      Paging:

      Private Sub dg_PageIndexCha nged(ByVal source As Object, ByVal e As
      System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
      dg.PageIndexCha nged
      dg.CurrentPageI ndex = e.NewPageIndex
      dg.DataBind()
      End Sub

      Comment

      • Cor Ligthert

        #4
        Re: Paging by example - help - still no luck....

        Tmuld,

        A webpage is not persistent, what means that with every send and get back
        all the data on serverside is removed. For that are some solutions for with
        is the session the most simple. The most simple because it can fit
        automatically (serialized) the dataset.

        Therefore you have to set that dataset again when there is a postback to the
        session (and as well when you do a fill to renew it).

        Your other question is what I am always struggling with as well, so take
        some time to find that.

        Cor


        Comment

        • Tmuldoon

          #5
          Re: Paging by example - help - still no luck....

          It is strange it is actually working in the background, but only
          appears after the search button is pressed again.

          I am thinking the currentrowindex is updated, but only will show when
          requeried.

          I thought the Databind() property refreshed to the new index.

          Still no luck....

          Comment

          • Cor Ligthert

            #6
            Re: Paging by example - help - still no luck....

            Tmuld,

            I made a complete working sample from that what I showed on MSDN in the
            link.

            Maybe you can try it.
            \\\Needs only a webdagrid.
            Private Sub Page_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArg s) Handles MyBase.Load
            Dim ds As DataSet
            DataGrid1.Allow Paging = True
            DataGrid1.Pager Style.Mode = PagerMode.Numer icPages
            DataGrid1.PageS ize = 5
            DataGrid1.Pager Style.PageButto nCount = 5
            If IsPostBack Then
            ds = DirectCast(Sess ion("dataset"), DataSet)
            DataGrid1.DataS ource = ds
            Else
            ds = New DataSet
            Dim dt As New DataTable
            dt.Columns.Add( "Mycolumn")
            For i As Integer = 0 To 100
            dt.LoadDataRow( New Object() {i.ToString}, True)
            Next
            ds.Tables.Add(d t)
            Session("datase t") = ds
            DataGrid1.DataS ource = ds
            DataBind()
            End If
            End Sub

            Private Sub DataGrid1_PageI ndexChanged(ByV al source As Object, ByVal e _
            As System.Web.UI.W ebControls.Data GridPageChanged EventArgs) _
            Handles DataGrid1.PageI ndexChanged
            DataGrid1.Curre ntPageIndex = e.NewPageIndex
            DataGrid1.DataB ind()
            End Sub
            ///

            I hope this helps a little bit?

            Cor


            Comment

            • Tmuld

              #7
              Re: Paging by example - help - still no luck....

              Hey Cor! I appreciate that!

              I tried that example - it is what I am using. I had to fiddle with the
              placement of the databinds.

              Of course now I have to get paging working and my select buttons on the
              side are ignored!

              Fix one thing - it leads to another issue!

              Thanks for your time and help!

              Tmuld

              Comment

              • Tmuld

                #8
                Re: Paging by example - help - still no luck....

                I mean sorting! Sorting is another strange animal.

                And trying to make my BACK button work so it doesn't clear the grid
                data and query. And of course asking the user to hit the 'back' button
                on the browser is a "no go").

                Tmuld

                Comment

                Working...