Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Langages serveur > ASP
ASP Forum sur la programmation ASP. Avant de poster : Cours ASP, FAQ ASP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/09/2006, 15h21   #1
Invité de passage
 
Inscription : août 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 16
Points : 3
Points : 3
Par défaut Pagination d'un tableau

Bonjour,

Dans la meme page , j'ai un tableau et en dessous uun formulaire pour remplir ce tableau.
Maintenant je voudrais paginer l'affichage de mon tableau, par ex afficher les 10 premiers enregistrements puis en cliquant sur suivant, afficher les 10 suivants.
Suite est un lien qui atterit sur la meme page. Mais comment peut-il recupere l'indice augmente ?
cela doit vous paraitre bien simple !

J'ai regarde tous les articles du forum et meme si j'ai trouve des post sur la pagination, aucun ne repondait à mes questions.

Je vous mets mon code, sans oublier les balises cette fois ci !
Voilà :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<html>
 
<head>
<meta http-equiv="Content-Language" content="fr">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>livredor2</title>
</head>
<body>
<%
' Création de l'objet permettant la connexion
Set Conn = Server.CreateObject("ADODB.Connection")
' Connexion
Conn.Open "test"%> <img border="0" src="livre.jpg"><p>&nbsp;</p>
<p>&nbsp;</p>
<div align="center">
  <center>
  <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-family:Verdana; font-size:8pt" bordercolor="#111111" width="411" id="AutoNumber1" bordercolorlight="#FF00FF">
    <tr>
      <td width="51"><font color="#0000FF">id-message</font></td>
      <td width="71"><font color="#0000FF">nom</font></td>
      <td width="109"><font color="#0000FF">message</font></td>
      <td width="51"><font color="#0000FF">date</font></td>
      <td width="123"><font color="#0000FF">adresse-mail</font></td>
    </tr>
    <%' Sélectionne toutes les fiches de la table "TLivre"
SQL="SELECT * FROM TLivre"
' indiquer le nombre de lignes par page
Set RS = server.createobject("ADODB.Recordset")
RS.Open SQL,Conn , 3, 3
'
<!--                            ="commentaire" -->
' tant qu'il y a des fiches
' pour pagination :
nbp = 6
i=0 'compteur du nombre de messages
while not RS.eof and i<nbp%>
<!--' while not RS.eof and i<10-->
 
    <tr>
      <td width="51"><%=RS("N°")%></a> &nbsp;</td>
      <td width="71"><%=RS("nom")%></a> &nbsp;</td>
      <td width="109"><%=RS("message")%> &nbsp;</td>
      <td width="51"><%=RS("dateL")%></a> &nbsp;</td>
      <td width="123"><%=RS("mail")%> &nbsp;</td>
      <!--webbot bot="PurpleText" PREVIEW="commentaire" -->
    </tr>
    <%
   RS.MOVENEXT ' fiche suivante
  i=i+1
wend%>
<% if not RS.eof then%>
<A href="?num=<%=i%>"> Suite </A>
<%end if%>
 
  </table>
  </center>
</div>
<% ' Deconnexion
 Conn.Close 
SET Conn=Nothing %>
<!-- description du formulaire -->&nbsp;<p align="right">
<a href="livredor2.asp"><span style="text-decoration: blink">
<font face="Verdana" size="1" color="#008000">Suite</font></span></a></p>
<p>&nbsp;</p>
<p align="center"><font face="Verdana" size="2">Ajouter des données à la base</font></p>
<form method="POST" action="livredor2.asp">
  <p align="center">&nbsp;</p>
  <!-- <p align="left"><font face="Verdana" size="2">Votre nom :</font>-->
  <input type="hidden" name="N°" value="0">
  <p align="left"><font face="Verdana" size="2">Votre nom :</font>
  <input type="text" name="nom" size="20"></p>
  <p align="left"><font face="Verdana" size="2">Votre message : </font>
  <input type="text" name="message" size="50"></p>
  <p align="left"><font face="Verdana" size="2">votre mail :
  <input type="text" name="mail" size="30"></font></p>
  <p align="left"><input type="submit" value="Envoyer" name="action">
  <input type="reset" value="Rétablir" name="B2"></p>
</form>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p>&nbsp;</p>
 
</body>
 
</html>
<!--  recuperation donnees formulaire --><% ' Création de l'objet permettant la connexion
Set Conn = Server.CreateObject("ADODB.Connection")
' Connexion
Conn.Open "test" %><!--
'   pour creation nouvelle ligne de table à partir du formulaire 
'        ------------------------------------------------------- 
   RS.addnew
   RS("nom")=Request.form("nom")
   RS("message")=Request.form("message")
   RS("mail")=Request.form("mail")
   RS("dateL")=now() 
   RS.update 
   If nom <> "" then
   ' passage--><% 
   nom=Request.form("nom")
   message=Request.form("message")
   mail=Request.form("mail") %><% if nom<>"" then%><% RequeteSQL = "Insert into TLivre (nom, message, dateL,mail) Values ('"&nom&"','"&message&"','"&now()&"','"&mail&"')"
    Set RS = server.createobject("ADODB.Recordset")
    RS.Open RequeteSQL,Conn , 3, 3
    response.redirect("livredor2.asp")
    %><%end if %><% ' Deconnexion
Set RS=Nothing
    Set nom=Nothing 
 Conn.Close 
Request.form("nom") 
 
SET Conn=Nothing %>
fgerard est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/09/2006, 16h17   #2
Membre régulier
 
Inscription : juillet 2005
Messages : 161
Détails du profil
Informations forums :
Inscription : juillet 2005
Messages : 161
Points : 92
Points : 92
passe un indice dans l'url quand tu veux changer de page pour le tableau sur l'appui du bouton suite

ex : nomdetapage.asp?i=indice

et ensuite tu recupère l'indice avec
Code :
ind=request.querystring("i")
et tu fais des condition d'affichage du tableau en fonction de ind
Mateache est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/09/2006, 16h46   #3
Invité de passage
 
Inscription : août 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 16
Points : 3
Points : 3
Merci, je vais essayer.
autre question : le Querystring est numerique ou texte ?
fgerard est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/09/2006, 09h23   #4
Membre régulier
 
Inscription : juillet 2005
Messages : 161
Détails du profil
Informations forums :
Inscription : juillet 2005
Messages : 161
Points : 92
Points : 92
ca depend de la variable que tu as passer dans l'url
Mateache est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/09/2006, 10h53   #5
Membre confirmé
 
Inscription : juin 2005
Messages : 412
Détails du profil
Informations personnelles :
Localisation : France, Paris (Île de France)

Informations forums :
Inscription : juin 2005
Messages : 412
Points : 261
Points : 261
Envoyer un message via MSN à mael94420
Le QueryString est comme son nom l'indique, toujours en "String" donc en chaine. Pour etre en numerique, utilise "cint"
mael94420 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/09/2006, 11h08   #6
Membre régulier
 
Inscription : juillet 2005
Messages : 161
Détails du profil
Informations forums :
Inscription : juillet 2005
Messages : 161
Points : 92
Points : 92
Citation:
Envoyé par mael94420
Le QueryString est comme son nom l'indique, toujours en "String" donc en chaine. Pour etre en numerique, utilise "cint"
exact c'est vrai qu'il faut utiliser Cint pour recuperer une var numerique j'y reflechirai a deux fois avant de repondre la prochaine fois merci mael
Mateache est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/09/2006, 14h17   #7
Invité de passage
 
Inscription : août 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 16
Points : 3
Points : 3
Merci de cette precision.
Je vous soumets à nouveau mon code car ma pagination ne fonctionne pas, ca ne fait rien.
J'ai ajoute des "response-write" qui l'indiquent bien que pour la 1ere page c'set OK, mais qu'apres, rien ne bouge !!

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<html>
 
<head>
<meta http-equiv="Content-Language" content="fr">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>livredor2</title>
</head>
<body>
<%
' Création de l'objet permettant la connexion
Set Conn = Server.CreateObject("ADODB.Connection")
' Connexion
Conn.Open "test"%> <img border="0" src="livre.jpg">
<p>&nbsp;</p>
<div align="center">
  <center>
  <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-family:Verdana; font-size:8pt" bordercolor="#111111" width="411" id="AutoNumber1" bordercolorlight="#FF00FF">
    <tr>
      <td width="51"><font color="#0000FF">id-message</font></td>
      <td width="71"><font color="#0000FF">nom</font></td>
      <td width="109"><font color="#0000FF">message</font></td>
      <td width="51"><font color="#0000FF">date</font></td>
      <td width="123"><font color="#0000FF">adresse-mail</font></td>
    </tr>
    <%' Sélectionne toutes les fiches de la table "TLivre"
SQL="SELECT * FROM TLivre"
' indiquer le nombre de lignes par page
Set RS = server.createobject("ADODB.Recordset")
RS.Open SQL,Conn , 3, 3
'
<!--                            ="commentaire" -->
' tant qu'il y a des fiches
' pour pagination :
' nbp : Nombre de lignes par page
' i = indice pour compter les lignes
' num = 
nbp = 6
num=cint(request.queryString("i"))%>
<BR> <%response.write "i= "%> <%=i%> </BR>
<%response.write "num avant le test = "%> <%=num%>
 
<% if num = 0 then
i=0 'compteur du nombre de messages
end if%>
<BR>
<%response.write "i avant la boucle = "%> <%=i%> </BR>
<%response.write "num apres le test= "%> <%=num%>
<BR>
<%response.write "  nbp+num= "%> <%=nbp+num%> </BR>
 
 
<% while not RS.eof and i<nbp+num%>
<!--' while not RS.eof and i<10-->
 
    <tr>
      <td width="51"><%=RS("N°")%></a> &nbsp;</td>
      <td width="71"><%=RS("nom")%></a> &nbsp;</td>
      <td width="109"><%=RS("message")%> &nbsp;</td>
      <td width="51"><%=RS("dateL")%></a> &nbsp;</td>
      <td width="123"><%=RS("mail")%> &nbsp;</td>
      <!--webbot bot="PurpleText" PREVIEW="commentaire" -->
    </tr>
    <%
   RS.MOVENEXT ' fiche suivante
  i=i+1
wend%>
<BR>
<%response.write "i apres la boucle = "%> <%=i%>
</BR>
 
<% if not RS.eof then%>
<A href="?num=<%=i%>"> Suite </A>
<%end if%>
 
  </table>
  </center>
</div>
<% ' Deconnexion
 Conn.Close 
SET Conn=Nothing %>
<!-- description du formulaire -->&nbsp;<p align="right">
<span style="text-decoration: blink">
<a href="livredor2.asp?num=i">
<font face="Verdana" size="1" color="#008000">Suite</font></a></span></p>
<p>&nbsp;</p>
<p align="center"><font face="Verdana" size="2">Ajouter des données à la base</font></p>
<form method="POST" action="livredor2.asp">
  <p align="center">&nbsp;</p>
  <!-- <p align="left"><font face="Verdana" size="2">Votre nom :</font>-->
  <input type="hidden" name="N°" value="0">
  <p align="left"><font face="Verdana" size="2">Votre nom :</font>
  <input type="text" name="nom" size="20"></p>
  <p align="left"><font face="Verdana" size="2">Votre message : </font>
  <input type="text" name="message" size="50"></p>
  <p align="left"><font face="Verdana" size="2">votre mail :
  <input type="text" name="mail" size="30"></font></p>
  <p align="left"><input type="submit" value="Envoyer" name="action">
  <input type="reset" value="Rétablir" name="B2"></p>
</form>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p>&nbsp;</p>
 
</body>
 
</html>
<!--  recuperation donnees formulaire --><% ' Création de l'objet permettant la connexion
Set Conn = Server.CreateObject("ADODB.Connection")
' Connexion
Conn.Open "test" %> 
    <% 
   nom=Request.form("nom")
   message=Request.form("message")
   mail=Request.form("mail") %><% if nom<>"" then%><% RequeteSQL = "Insert into TLivre (nom, message, dateL,mail) Values ('"&nom&"','"&message&"','"&now()&"','"&mail&"')"
    Set RS = server.createobject("ADODB.Recordset")
    RS.Open RequeteSQL,Conn , 3, 3
    response.redirect("livredor2.asp")
    %><%end if %><% ' Deconnexion
Set RS=Nothing
    Set nom=Nothing 
 Conn.Close 
Request.form("nom") 
 
SET Conn=Nothing %>
fgerard est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/09/2006, 09h01   #8
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
Citation:
Envoyé par Mateache
exact c'est vrai qu'il faut utiliser Cint pour recuperer une var numerique j'y reflechirai a deux fois avant de repondre la prochaine fois merci mael
Pas forcement. En ASP les variables ne sont pas typées. Bien entendu les pages recoivent toujours une chaine de caractères, mais ASP les analyse tout seul. Par exempledonne 4.

A+
Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/09/2006, 09h31   #9
Membre régulier
 
Inscription : juillet 2005
Messages : 161
Détails du profil
Informations forums :
Inscription : juillet 2005
Messages : 161
Points : 92
Points : 92
Citation:
Envoyé par Immobilis
Pas forcement. En ASP les variables ne sont pas typées. Bien entendu les pages recoivent toujours une chaine de caractères, mais ASP les analyse tout seul. Par exempledonne 4.

A+
Oui mais quand tu recupère un request.querystring si tu veux faire un test genre
Code :
If request.querystring("var")=10 then
Meme si var est une varaible numérique il faudra mettre un Cint. Je peux me tromper mais j'ai toujours eu des type mismatch si je met pas le Cint.
Mateache est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/09/2006, 10h41   #10
Invité de passage
 
Inscription : août 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 16
Points : 3
Points : 3
J'ai compris (enfin je crois) que pour la pagination je dois transmettre mon nouvel indice dans l'URL.
1ere question :
Dois-je faire ce transfert dans mon pgm par :
Code :
1
2
3
<% if not RS.eof then%>
<A href="?num=<%=request.queryString("i")%>"> Suite </A>
<%end if%>
Ou dans le parametrage de mon lien hyper texte dans Front page.

D'ailleurs pour l'instant je fais les 2 et je ne pense pas que ce soit OK.

Autre chose : J'ai l'impression que je transfere i et non sa valeur !?

Merci de votre aide
fgerard est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/09/2006, 11h38   #11
Membre régulier
 
Inscription : juillet 2005
Messages : 161
Détails du profil
Informations forums :
Inscription : juillet 2005
Messages : 161
Points : 92
Points : 92
le request.querystring te permet de récuperer la valeur que tu as passé dans l'URL. Pour ton bouton suite il faudrai definier une valeur qui te dise que si le request.querystring("i")=lavaleur alors on change de page dans le tableau

Il faut donc mettre
Code :
<A href="?num=unevaleur>"> Suite </A>
Mateache est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/09/2006, 11h51   #12
Expert Confirmé
 
Avatar de pc75
 
Inscription : septembre 2004
Messages : 2 807
Détails du profil
Informations personnelles :
Âge : 56
Localisation : France, Paris (Île de France)

Informations forums :
Inscription : septembre 2004
Messages : 2 807
Points : 3 005
Points : 3 005
Bonjour,

Voilà le code que j'utilise pour faire mes paginations :

Page qui affiche les données
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
 
<!--#include file="../Includes/PageNavBar.inc"-->
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>Gestion des Agents</title>
</head>
<body bgcolor="#fefceb">
.....
<%
SQLtemp = ""
SQLtemp = SQLtemp & "select * "
SQLtemp = SQLtemp & "from TBL_AGENTS "
SQLtemp = SQLtemp & "order by AGT_NOM, AGT_PRENOM"
'on error resume next
 
mypage = request("whichpage")
If  mypage = "" then
   mypage = 1
end if
mypagesize = request("pagesize")
If  mypagesize = "" then
   mypagesize = 20
end if
mySQL = request("SQLquery")
IF  mySQL = "" THEN
   mySQL = SQLtemp
END IF
 
set rstemp = Server.CreateObject("ADODB.Recordset")
rstemp.cursorlocation = aduseclient
rstemp.cachesize = 5
rstemp.open mysql, Application("DsnODBC")
%>
.....
	<%
	if not rstemp.EOF then
	   rstemp.movefirst
 
		rstemp.pagesize = mypagesize
		maxpages = cint(rstemp.pagecount)
		maxrecs = cint(rstemp.pagesize)
		rstemp.absolutepage = mypage
		howmanyrecs = 0
		%>
 
		<table align="center" border="1" width="100%">
			<%
			Str_Compteur = 0
			DO  UNTIL rstemp.eof OR howmanyrecs >= maxrecs
.....
				<%
				rstemp.MoveNext
	 			howmanyrecs = howmanyrecs + 1
			loop
			%>
		</table>
		<br><br>
		<%
		Call PageNavBar
	end if
	rstemp.Close
	set rstemp = Nothing
	%>

Le fichier include (PageNavBar.inc)
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
<%
sub PageNavBar()
    pad=""
    scriptname=request.servervariables("script_name")
    response.write "<table border='0' align='center' rows='1' cols='1' width='97%'><tr>"
    response.write "<td>"
    response.write "<font size='2' color='black' face='Verdana, Arial,Helvetica,sans-serif'>"
    if (mypage mod 10) = 0 then
		counterstart = mypage - 9
    else
		counterstart = mypage - (mypage mod 10) + 1
    end if
    counterend = counterstart + 9
	Response.Write "<center>"
    if counterend > maxpages then counterend = maxpages
    if counterstart <> 1 then
		ref="<a href='" & scriptname
		ref=ref & "?whichpage=" & 1
		ref=ref & "&pagesize=" & mypagesize
		ref=ref & "&sqlQuery=" & server.URLencode(mySQL)
		ref=ref & "'>Première</a>&nbsp;:&nbsp;"
		Response.Write ref
 
		ref="<a href='" & scriptname
		ref=ref & "?whichpage=" & (counterstart - 1)
		ref=ref & "&pagesize=" & mypagesize
		ref=ref & "&sqlQuery=" & server.URLencode(mySQL)
		ref=ref & "'>Précédente</a>&nbsp;"
		Response.Write ref
    end if
 
    Response.Write "["
    for counter=counterstart to counterend
		If counter>=10 then
			pad=""
		end if
		if cstr(counter) <> mypage then
			ref="<a href='" & scriptname
			ref=ref & "?whichpage=" & counter
			ref=ref & "&pagesize=" & mypagesize
			ref=ref & "&sqlQuery=" & server.URLencode(mySQL)
			ref=ref & "'>" & pad & counter & "</a>"
		else
			ref="<b>" & pad & counter & "</b>"
		end if
		response.write ref
		if counter <> counterend then response.write " "
    next
    Response.Write "]"
    if counterend <> maxpages then
		ref="&nbsp;<a href='" & scriptname
		ref=ref & "?whichpage=" & (counterend + 1)
		ref=ref & "&pagesize=" & mypagesize
		ref=ref & "&sqlQuery=" & server.URLencode(mySQL)
		ref=ref & "'>Suivante</a>"
		Response.Write ref
 
		ref="&nbsp;:&nbsp;<a href='" & scriptname
		ref=ref & "?whichpage=" & maxpages
		ref=ref & "&pagesize=" & mypagesize
		ref=ref & "&sqlQuery=" & server.URLencode(mySQL)
		ref=ref & "'>Dernière</a>"
		Response.Write ref
    end if
    response.write "<br></font>"
    response.write "</td>"
    response.write "</tr>"
    response.write "</table>"
end sub
%>
__________________
Par principe, je ne réponds pas aux messages URGENT.
Il n'y a pas de choses urgentes, il n'y a que des choses en retard. (un inconnu)
pc75 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 08h03.


 
 
 
 
Partenaires

Hébergement Web