Click here to Skip to main content
13,000,636 members (57,561 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have done paging in Datalist using MySql database , it is working well but there is one issue i.e
if i am searching products i.e( selecting categories from dropdownlist) then it fetch all items that are related to product , then i go to second page by clicking on next button , but if i select other category to search it fetch the data in the previous page where i was searching mean on second page where i was previously.
i.e if i am on second page , then the data fetch will be on second page ,it doesn't start from first page to fetch data it remain on that page , so if some category doesn't have data , it still showing 2 page of 1 pages, and if click on next button it will show showing 3 page of 1 pages and so on .
What is this issue can anybody solve it .............
Code below to understand it .........

<pre lang="vb">
Imports MySql.Data.MySqlClient
Imports System.Data

  Dim cn As New MySqlConnection
    Dim cd As MySqlCommand
    Dim s, f, g, b, city As String
    Dim r, d, d1 As MySqlDataReader
    Dim da As New MySqlDataAdapter
    Dim ds As New DataSet
    Dim pg As New PagedDataSource
    Dim p As Integer

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
Sub bind()
cn.ConnectionString = &quot;server=localhost ; user id=root; password=; database=**&quot;
            s = &quot;select name,emp_add,opno,pno,eds,wl,type from main where  product=&#39;&quot; &amp; DropDownList1.SelectedItem.Text &amp; &quot;&#39; ORDER BY name &quot;
            cd = New MySqlCommand(s, cn)
            da.SelectCommand = cd
            pg.DataSource = ds.Tables(0).DefaultView
            pg.AllowPaging = True
            pg.PageSize = 10
            pg.CurrentPageIndex = CurrentPage
            Label2.Text = &quot;Showing Page: &quot; &amp; (CurrentPage + 1).ToString() &amp; &quot; of &quot; &amp; pg.PageCount.ToString()
            Button2.Enabled = Not pg.IsFirstPage
            Button3.Enabled = Not pg.IsLastPage
            DataList1.DataSource = pg
End Sub

 Public Property CurrentPage() As Integer
            Dim s1 As Object = Me.ViewState("CurrentPage")
            If s1 Is Nothing Then
                Return 0
                Return CInt(s1)
            End If
        End Get
        Set(ByVal value As Integer)
            Me.ViewState("CurrentPage") = value
        End Set
    End Property

 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        CurrentPage -= 1
    End Sub
    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        CurrentPage += 1
    End Sub
Posted 7-Jan-13 0:58am
Updated 7-Jan-13 16:39pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

When someone changes the data in any way, you need to set 'CurrentPage' to 0, or 1, whatever the default is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100