Articoli Referenze Script FAQ Downloads ASP E-Commerce con ASP Menu Javascript Area Aziende Cocktail Registrazione domini



Paginazione a colonne sui record di un database in ASP

Home + Articoli + Database e SQL + Articolo # 143
Autore: Luca Ruggiero

Concesso in esclusiva a Mr.Webmaster. Vietata la riproduzione.


All'atto dell'estrazione di record da un database siamo abituati a disporre i record in orizzontale o in verticale, impaginandoli in genere in una tabella HTML.

Abbiamo la possibilità di impostare i record a colonne, impaginandoli in N colonne ed N record (a seconda del numero di record presenti nel database) semplicemente impostando un contatore a zero (0) e verificando che arrivi al numero di colonne preferito.

Il file di database database.mdb e data la tabella utenti, composta dal solo campo nome, impostiamo nelle nostre pagine ASP il seguente script opportunamente commentato:
<%@LANGUAGE = VBScript%>
<%
    ' DEFINISCO LE VARIABILI CHE MI SERVONO PER L'APPLICAZIONE
    Dim sc, cn, rs, contatore

    ' DEFINISCO LA STRINGA DI CONNESSIONE
    sc = ""
    sc = sc & "driver={Microsoft Access Driver (*.mdb)};dbq="
    sc = sc & Server.MapPath("database.mdb")

    ' IMPOSTO LA CONNESSIONE EDIL RECORDSET
    Set cn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.Recordset")

    ' APRO LA CONNESSIONE COL DATABASE
    cn.Open sc
%>
<html>
<head>
<title>Paginazione a colonne sui record di un db in ASP</title>
</head>
<body>

<table border="1"><tr>
<%
    ' IMPOSTO A 0 IL CONTATORE
    contatore = 0
    ' APRO IL RECORDSET
    rs.Open "SELECT nome FROM utenti ORDER BY nome ASC", cn, 1
    ' ESEGUO IL CICLO
    While rs.EOF = False
        ' IMPOSTO LA PAGINAZIONE A 3 COLONNE ED N RIGHE
        ' IN FUNZIONE DEL NUMERO DI RECORD PRESENTI NEL DB
        If contatore = 3 Then
            contatore = 0
            Response.Write "</tr><tr>"
        End If
%>
    <td><%=rs("nome")%></td>
<%
        rs.MoveNext
        ' INCREMENTO IL VALORE DEL CONTATORE
        contatore = contatore + 1
    Wend
    rs.Close
%>
</tr></table>

</body>
</html>
<%
    ' UN PO DI PULIZIA...
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
%>
© 2008 ASP Center di Luca Ruggiero - P. IVA 05564851219 - Disclaimer | Privacy | Pubblicità | Supportaci | Staff | Contatti
  Appunti PHP | Giornale Webmaster | Mr.Webmaster | Download | DevSpy.com | ASPCode.it | ClaudioGarau.it | Webmaster Facile | Come Faccio | CodiceFacile.it | I Programmatori | By Luciani | VoiceXML Italian User Group | Giochi | Extro Web Site | Morpheus Web | AG Web Solutions | Net-Free | PC Sicuro | PC Self | Tutorial Web | Dablones