Por exemplo, vamos fazer uma pesquisa no banco de dados:
a paginacao vai rolar assim:
<< 1, 2, 3, 4, ..., 10, 11, 12, ... 20, 21, 22 >>
como sei q mtos querem isso tah aki o cod.
paginacao.asp
<% 'conexao com o banco de dados - no exemplo aqui é por mysql Set conexao = Server.CreateObject("ADODB.connection") conexao.open ("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=teste;UID=root;") 'config npaginas = 30 'numero de resultados nomedapagina = "paginacao.asp" 'nome da propria pagina onde vai rola a paginacao cordolink = "#000000" 'cor dos links da paginacao fontedolink = "tahoma" 'fonte dos links da paginacao tamanhodafontelink = "11px" 'tamanho da fonte dos links da paginacao 'vai passando as paginas - nao altere pagina = clng(request.querystring("pagina")) * clng(npaginas) 'consulta - altere de acordo com seu banco set rs = conexao.execute("SELECT nome FROM clientes LIMIT " & pagina & "," & npaginas & ";") 'contagem - altere de acordo com seu banco set rscontar = conexao.execute("SELECT count(nome) AS total FROM clientes;") if rs.eof then 'se nao achar nada: response.write "nada encontrado!" else response.write "Clientes encontrados: <b>" & rscontar("total") & "</b><br><Br>" 'se achar ele mostra todos do while not rs.eof response.write rs("nome") & "<br>" rs.movenext loop 'apos o loop ele monta a paginacao response.write Paginacao(rscontar("total"), clng(npaginas), nomedapagina, cordolink, fontedolink, tamanhodafontelink) end if 'fecha conexao de contagem rscontar.close set rscontar = nothing 'fecha conexao de consulta rs.close set rs = nothing 'fecha conexao com o db conexao.close set conexao = nothing '=============================================== 'funcao de paginacao '=============================================== Function Paginacao(numerodepaginas,varpagina,link,corlink,fonte,tamanho) TextoSaidaHtml = "<table align=right style=""fonte-size:" & tamanho & ";fonte-family:" & fonte & ";color:" & corlink & """><tr><Td valign=top align=right><font face=tahoma style=font-size:11px><font color=#000000>Página(s):</font> <font face=tahoma style=font-size:11px>« " npaginas = (clng(numerodepaginas) / clng(varpagina)) i = 0 for i = 0 to clng(16) if npaginas <= 15 then else if i > 4 then exit for end if end if if clng(request.querystring("pagina")) = clng(i) then if i = 0 then TextoSaidaHtml = TextoSaidaHtml & " " & (i + 1) & " " else TextoSaidaHtml = TextoSaidaHtml & ", " & (i + 1) & " " end if else if i = 0 then TextoSaidaHtml = TextoSaidaHtml & " <a style=""fonte-size:" & tamanho & ";fonte-family:" & fonte & ";color:" & corlink & """ href=""" & link & "?pagina=" & i & """><u>" & (i + 1) & "</u></a> " else TextoSaidaHtml = TextoSaidaHtml & ", <a style=""fonte-size:" & tamanho & ";fonte-family:" & fonte & ";color:" & corlink & """ href=""" & link & "?pagina=" & i & """><u>" & (i + 1) & "</u></a> " end if end if if clng(numerodepaginas) <= clng((clng(i) * varpagina) + varpagina) then vercontador = i exit for end if next if npaginas <= 15 then if clng(request.querystring("pagina")) = clng(vercontador) then TextoSaidaHtml = TextoSaidaHtml & " »<table><tr><td></td></tr></table>Resultados de <strong>" & (pagina + 1) & "</strong> até <strong>" & numerodepaginas & "</strong>" else TextoSaidaHtml = TextoSaidaHtml & " »<table><tr><td></td></tr></table>Resultados de <strong>" & (pagina + 1) & "</strong> até <strong>" & (pagina + varpagina) & "</strong>" end if TextoSaidaHtml = TextoSaidaHtml & "</TD></tr></table>" exit function end if if clng(request.querystring("pagina")) < 4 then TextoSaidaHtml = TextoSaidaHtml & ", ... " end if if clng(request.querystring("pagina")) > clng(npaginas-3) then TextoSaidaHtml = TextoSaidaHtml & ", ... " end if if clng(request.querystring("pagina")) => 4 AND clng(request.querystring("pagina")) <= clng(npaginas-3) then i = 0 iz = 0 if clng(request.querystring("pagina")) > 5 then TextoSaidaHtml = TextoSaidaHtml & ", ... " end if for i = (request.querystring("pagina")-1) to clng(request.querystring("pagina")+1) iz = iz + 1 if clng(i) => 5 AND clng(i) < clng(npaginas-3) then if clng(request.querystring("pagina")) = clng(i) then TextoSaidaHtml = TextoSaidaHtml & ", " & (i + 1) & " " else TextoSaidaHtml = TextoSaidaHtml & ", <a style=""fonte-size:" & tamanho & ";fonte-family:" & fonte & ";color:" & corlink & """ href=""" & link & "?pagina=" & i & """><u>" & (i + 1) & "</u></a> " end if if iz = 3 then TextoSaidaHtml = TextoSaidaHtml & ",..." end if end if next end if '################################################### i = 0 for i = clng(npaginas-3) to clng(npaginas) if clng(request.querystring("pagina")) = clng(i) then TextoSaidaHtml = TextoSaidaHtml & ", " & (i + 1) & " " else TextoSaidaHtml = TextoSaidaHtml & ", <a style=""fonte-size:" & tamanho & ";fonte-family:" & fonte & ";color:" & corlink & """ href=""" & link & "?pagina=" & i & """><u>" & (i + 1) & "</u></a> " end if if clng(numerodepaginas) <= clng((clng(i) * varpagina) + varpagina) then vercontador = i exit for end if next '################################################### if clng(request.querystring("pagina")) = clng(vercontador) then TextoSaidaHtml = TextoSaidaHtml & " »<table><tr><td></td></tr></table>Resultados de <strong>" & (pagina + 1) & "</strong> até <strong>" & numerodepaginas & "</strong>" else TextoSaidaHtml = TextoSaidaHtml & " »<table><tr><td></td></tr></table>Resultados de <strong>" & (pagina + 1) & "</strong> até <strong>" & (pagina + varpagina) & "</strong>" end if TextoSaidaHtml = TextoSaidaHtml & "</TD></tr></table>" Paginacao = TextoSaidaHtml End Function '=============================================== %>
boa programacao pra vcs!
[]'s
-----------------------------------------------------------------------------------------------
Para uma maior organização desta seção, todas as duvidas relacionadas a este tutorial devem ser tiradas na seguinte sala:
http://forum.wmonlin...p?showforum=113
Edição feita por: Agente Linhares, 28/06/2005, 22:57.