Torna al Thread
Sub BindData()
connetti()
' stringa di connessione
'Dim strconn As String = "server=localhost;database=" & Server.MapPath(".") & ConfigurationSettings.AppSettings("nomeDB") & ";trusted_connection=true;"
' query
Dim strsql As String = "SELECT * FROM GuestBook "
' SqlConnection e SqlDataAdapter
'Dim conn As SqlConnection = New SqlConnection(strConn)
'Dim query As SqlDataAdapter = New SqlDataAdapter(strsql, conn)
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")
guest.DataSource = querydataset
guest.DataBind()
' conta i record totali
Dim strSQLCount As String = strSQL
' ricavo la query count
strSQLCount = "SELECT COUNT(*) as Totale " & strSQLCount.Substring(strSQLCount.IndexOf(" FROM "))
'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 Messaggio"
Else
results.Text += TotalSize & " messaggi"
End If
' fix per record finale
Dim EndRecords As Integer
EndRecords = startRecord + Int32.Parse(PageSize)
If EndRecords > TotalSize Then EndRecords = TotalSize
results.Text += " - Pagina " & CurrentPage & " di " & TotalPages
'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
Dim paginelink As String
If TotalPages > 1 Then
lb = New Label()
lb.Text = paginelink
paginelink = "Ci sono " & TotalPages & " pagine "
paginazione.controls.add(lb)
For i = 1 To (TotalPages)
'lb = New Label()
'lb.id = "ThisPage" & i
If currentPage = i Then
paginelink = paginelink & "[" & i & "] "
Else
'lb.Text = "[<a href=""" & Request.PathInfo.ToString & "?p=" & i & """>" & i & "</a>] "
paginelink = paginelink & " <a href=""guestbook.aspx?p=" & i & """>[" & i & "]</a> "
End If
lb.Text = paginelink
Paginazione.Controls.Add(lb)
Next
End If
End Sub