Ho provato ad adattare lo sript ma non funziona.
Potete aiutarmi nel capire l'errore.
Grazie e ciao
codice:
<%@ Page Language="VB" Debug="true" %>
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<script runat="server">
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")
Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\test\asp_net\db\banking.mdb"
' query
Dim strSQL As String = "SELECT * FROM tblUsers"
' 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 tblUsers"
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
</SCRIPT>
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
<asp:datalist ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand"
SelectedItemStyle-BackColor="#99cc99"
repeatlayout="Table"
repeatdirection="Horizontal"
DataKeyField="UserID"
AllowPaging="true"
PageSize=2
PagerStyle-Mode=NumericPages
PagerStyle-PageButtonCount=2
OnPageIndexChanged="DataList1_PageIndexChanged">
<itemtemplate>
<asp:linkbutton ID="button1" runat="server"
Text='<%# Container.DataItem("FirstName") & " " & Container.DataItem("LastName") %>'
CommandName="Select" />
</itemtemplate>
<selecteditemtemplate>
<%# Container.DataItem("FirstName") & " " & Container.DataItem("LastName") %>
Phone:
<%# Container.DataItem("Phone") %>
Address:
<%# Container.DataItem("Address") %>
<%# Container.DataItem("City") %>
<%# Container.DataItem("State") %>
<%# Container.DataItem("ZIP") %>
</selecteditemtemplate>
</asp:datalist>
</form>
</body>
</html>