ciao,
ho notato che questa paginazione mi si mangia un record. perciò se nella tabella c'è un solo record non lo visualizzo perchè?
codice:
Protected WithEvents queryres As System.Web.UI.WebControls.Repeater
Protected WithEvents results As System.Web.UI.WebControls.Label
Protected WithEvents paginazione As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents form1 As System.Web.UI.HtmlControls.HtmlForm
Dim PageSize As Integer = 10
Dim CurrentPage As String
Dim TotalPages, TotalSize As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' pagina corrente
CurrentPage = Request("p")
If CurrentPage Is Nothing Then CurrentPage = 1
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
' stringa di connessione
Dim strconn As String = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("mdb-database/db.mdb")
' query
Dim strSQL As String = "SELECT * FROM tb"
' SqlConnection e SqlDataAdapter
Dim conn As OleDbConnection = New OleDbConnection(strconn)
Dim query As OleDbDataAdapter = New OleDbDataAdapter(strSQL, conn)
' creo il dataset
Dim querydataset As DataSet = New DataSet
Dim startRecord As Integer = (Int32.Parse(CurrentPage) - 1) * Int32.Parse(PageSize)
' databinding
query.Fill(querydataset, startRecord, Int32.Parse(PageSize), "ext_content")
queryres.DataSource = querydataset
queryres.DataBind()
' conta i record totali
Dim strSQLCount As String
' ricavo la query count
strSQLCount = "SELECT COUNT(*) as Totale FROM tb"
conn.Open()
Dim myCommand As OleDbCommand = New OleDbCommand(strSQLCount, conn)
Dim reader As OleDbDataReader = myCommand.ExecuteReader()
' conto i risultati
reader.Read()
TotalSize = reader("totale")
reader.Close()
conn.Close()
' mostra avviso in alto con il numero dei risultati
If TotalSize = 0 Then
results.Text = "Non ci sono risultati per questa ricerca"
Else
TotalPages = Int32.Parse(TotalSize) \ Int32.Parse(PageSize) + 1
' fix per numero di pagine
If Fix(TotalSize / PageSize) = TotalSize / PageSize Then TotalPages = TotalPages - 1
If TotalSize = 1 Then
results.Text = "Un risultato"
Else
results.Text = TotalSize & " risultati"
End If
' fix per record finale
Dim EndRecords As Integer = startRecord + Int32.Parse(PageSize)
If EndRecords > TotalSize Then EndRecords = TotalSize
results.Text = results.Text & " - Pagina " & CurrentPage & " su " & TotalPages & " in totale - da " & startRecord + 1 & " a " & EndRecords
End If
If TotalSize = 0 Then
paginazione.Visible = False
End If
' costruisci la paginazione
BuildPagers()
End Sub
Sub BuildPagers()
' ciclo
Dim i As Integer
Dim lb As Label
If TotalPages > 1 Then
lb = New Label
lb.Text = "Pagina: "
paginazione.Controls.Add(lb)
For i = 1 To (TotalPages)
lb = New Label
lb.ID = "Pagina" & i
If CurrentPage = i Then
lb.Text = "[" & i & "] " & vbCrLf
Else
lb.Text = "[" & i & "] " & vbCrLf
End If
Paginazione.Controls.Add(lb)
Next
End If
End Sub
lo potete provare e farmi sapere?