non so se ti può interessare ma io mi sto guardando oltre che il tuo script anche questo:
ricerca.ascx
codice:
<%@ Control debug="true"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SQLClient"%>
<SCRIPT LANGUAGE="VB" RUNAT="SERVER">
Dim PageSize as Integer = 1
Dim CurrentPage as string
Dim TotalPages as Integer
Dim TotalSize as Integer
' PUBLIC
Dim Public Chiave as String
Sub Page_Load(sender As Object, e As EventArgs)
' recupero chiave da querystring se non è passata dal control
if chiave is nothing then
chiave = Request("chiave")
end if
' 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/fg-tunisie.mdb")
' query
Dim strSQL as String = "SELECT * FROM Prodotti WHERE Categoria LIKE '%" & chiave.Replace("'", "''") & "%'"
' 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 = strSQL
' ricavo la query count
strSQLCount = "SELECT COUNT(*) as Totale " & strSQLCount.SubString(strSQLCount.IndexOf(" FROM Prodotti WHERE Categoria LIKE '%" & chiave.Replace("'", "''") & "%'"))
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 EndRecors as Integer = startRecord + int32.Parse(PageSize)
if EndRecords > TotalSize then EndRecords = TotalSize
results.text += " - Pagina " & CurrentPage & " su " & TotalPages & " in totale - da " & startRecord+1 & " a " &
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 = "Ci sono " & TotalPages & " pagine con i risultati: "
paginazione.controls.add(lb)
for i = 1 to (TotalPages)
lb = New Label()
lb.id = "ThisPage" & 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>
<asp:label id="results" runat="server"/>
<asp:repeater id="queryres" runat="server">
<itemTemplate>
<%#Container.DataItem("codice")%> -
<%#Container.DataItem("titolo")%>
</itemTemplate>
</asp:repeater>
<asp:placeholder id="Paginazione" runat="server"/>
ricerca.aspx
codice:
<%@ Register TagPrefix="tools" TagName="ricerca" src="ricerca.ascx"%>
<h1>Ricerca</h1>
<tools:ricerca chiave="gomme" runat="server"/>