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
ds.Clear()
bind()
End Sub
Sub bind()
cn.ConnectionString = "server=localhost ; user id=root; password=; database=**"
cn.Open()
s = "select name,emp_add,opno,pno,eds,wl,type from main where product='" & DropDownList1.SelectedItem.Text & "' ORDER BY name "
cd = New MySqlCommand(s, cn)
da.SelectCommand = cd
da.Fill(ds)
pg.DataSource = ds.Tables(0).DefaultView
pg.AllowPaging = True
pg.PageSize = 10
pg.CurrentPageIndex = CurrentPage
Label2.Text = "Showing Page: " & (CurrentPage + 1).ToString() & " of " & pg.PageCount.ToString()
Button2.Enabled = Not pg.IsFirstPage
Button3.Enabled = Not pg.IsLastPage
DataList1.DataSource = pg
DataList1.DataBind()
cn.Close()
End Sub
Public Property CurrentPage() As Integer
Get
Dim s1 As Object = Me.ViewState("CurrentPage")
If s1 Is Nothing Then
Return 0
Else
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
bind()
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
CurrentPage += 1
bind()
End Sub
</pre>