10/10/2018, 11:14

ASP: Giúp mình phân trang đoạn code này. thank nhiều

Mình có đoạn code như sau:

<%
Dim rs,i,dk,dem
set rs=server.createObject("ADODB.Recordset")
dk=request.QueryString("m_loai")
if dk<>"" then
SQLstring="select * from Hanghoa where maloai="& dk
rs.open SQLstring,conn
else
SQLstring="select * from hanghoa"
rs.open SQLstring,conn
end if
dem=0
%>
<table width="100%" border="0" >
<tr>
<td>
<table width="100%" border="1" align="center" bordercolor="#990066">
<% do while not rs.EOF %>
<tr>
<%
if dem <13 then '5 thi 2 dong, 9 : 3 dong, 13: 4 dong; 17: 5 dong.
for i = 1 to 4
dem=dem+1
If rs.EOF=False AND rs.BOF=False then
%>
<td ><div align="center"><%=rs("TenSP")%></div>
<p align="center"><img src=<%=rs("hinh")%> width="124" height="113" /> <p align="center"> <a href="chitietHang.asp?masanpham='<%=rs("maSP")%>'" >Chi tiết</td>
<%
rs.movenext
else
exit for
exit do
end if
next
%>
</tr>
</table>
<table width="100%" border="1" bordercolor="#990066">
<tr>
<% else %>
<td><a href="chitietHang.asp?masanpham='<%=rs("maSP")%>'" ><%=rs("tenSP")%> </a></td>
<%
rs.movenext
end if
loop
%>
</tr>
</table>
</tr>
</table>

giờ muốn nó hiển thị 16 sản phẩm mỗi trang . rồi làm 1 nút next, số hoặc dấu > để qua trang khác hiển thị tiếp 16 sản phẩm tiếp theo mình phải sữa lại như thế nào
Cactuslonely viết 13:23 ngày 10/10/2018
<%
set g = request.QueryString
Dim rs,i,dk,dem
set rs=server.createObject("ADODB.Recordset")
dk=g("m_loai")
if dk<>"" then
SQLstring="select * from Hanghoa where maloai="& dk
rs.open SQLstring,conn
else
SQLstring="select * from hanghoa"
rs.open SQLstring,conn
end if
dem=0
rs.pagesize = 16

rs.AbsolutePage=trang


tongso=rs.PageCount
%>
<table width="100%" border="0" >
<tr>
<td>
<table width="100%" border="1" align="center" bordercolor="#990066">
<% do while not rs.EOF %>
<tr>
<%
if dem <13 then '5 thi 2 dong, 9 : 3 dong, 13: 4 dong; 17: 5 dong.
for i = 1 to 4
dem=dem+1
If rs.EOF=False AND rs.BOF=False then
%>
<td ><div align="center"><%=rs("TenSP")%></div>
<p align="center"><img src=<%=rs("hinh")%> width="124" height="113" /> <p align="center"> <a href="chitietHang.asp?masanpham='<%=rs("maSP")%>'" >Chi tiết</td>
<%
rs.movenext
else
exit for
exit do
end if
next
%>
</tr>
</table>
<table width="100%" border="1" bordercolor="#990066">
<tr>
<% else %>
<td><a href="chitietHang.asp?masanpham='<%=rs("maSP")%>'" ><%=rs("tenSP")%> </a></td>
<%
rs.movenext
end if
loop
%>
</tr>
</table>
</tr>
</table>
<%if trang>1 then%>
<a href="search.asp?kieu=<%=kieu%>&tim=<%=chuyendoi%> &trang=<%=trang-1%>"><< Tr***432;***7899;c</a>
<%
else%>
<%end if%>
<% if tongso=1 then
response.write""
else%>
<%
i=1
Do while i<=tongso
if i=trang then
Response.write "[ -"&i&"- ]"
else
Response.write "<A href=?trang="&i&">[ -"&i&"- ]</a>"
end if
i=i+1
Loop
end if
if not rs.EOF then%>
<a href="?trang=<%=trang+1%>">Ti***7871;p >></a>
<%
else
response.write""
end if
rs.close
%>

[=========> Bổ sung bài viết <=========]

<%
set g = request.QueryString
Dim rs,i,dk,dem
set rs=server.createObject("ADODB.Recordset")
dk=g("m_loai")
if dk<>"" then
SQLstring="select * from Hanghoa where maloai="& dk
rs.open SQLstring,conn
else
SQLstring="select * from hanghoa"
rs.open SQLstring,conn
end if
dem=0
rs.pagesize = 16

rs.AbsolutePage=trang


tongso=rs.PageCount
%>
<table width="100%" border="0" >
<tr>
<td>
<table width="100%" border="1" align="center" bordercolor="#990066">
<% do while not rs.EOF %>
<tr>
<%
if dem <13 then '5 thi 2 dong, 9 : 3 dong, 13: 4 dong; 17: 5 dong.
for i = 1 to 4
dem=dem+1
If rs.EOF=False AND rs.BOF=False then
%>
<td ><div align="center"><%=rs("TenSP")%></div>
<p align="center"><img src=<%=rs("hinh")%> width="124" height="113" /> <p align="center"> <a href="chitietHang.asp?masanpham='<%=rs("maSP")%>'" >Chi tiết</td>
<%
rs.movenext
else
exit for
exit do
end if
next
%>
</tr>
</table>
<table width="100%" border="1" bordercolor="#990066">
<tr>
<% else %>
<td><a href="chitietHang.asp?masanpham='<%=rs("maSP")%>'" ><%=rs("tenSP")%> </a></td>
<%
rs.movenext
end if
loop
%>
</tr>
</table>
</tr>
</table>
<%if trang>1 then%>
<a href="?trang=<%=trang-1%>"><< Truoc</a>
<%
else%>
<%end if%>
<% if tongso=1 then
response.write""
else%>
<%
i=1
Do while i<=tongso
if i=trang then
Response.write "[ -"&i&"- ]"
else
Response.write "<A href=?trang="&i&">[ -"&i&"- ]</a>"
end if
i=i+1
Loop
end if
if not rs.EOF then%>
<a href="?trang=<%=trang+1%>">Tiep >></a>
<%
else
response.write""
end if
rs.close
%>
skyearths viết 13:15 ngày 10/10/2018
thank bạn nhiều. nhưng test vận lỗi
Hanghoa5.asp, line 16: rs.AbsolutePage=trang
bạn có thể cho mình yahoo ko
Cactuslonely viết 13:20 ngày 10/10/2018
que^n hihi!!
them dong: trang = g("trang") sau dong: set g = request.QueryString la ok
sangthanh8309 viết 13:15 ngày 10/10/2018
lam gi ghe vay:trong asp dot net da ho tro roi ma:chon properties-->First page,Last Page...
VD:ban chon 5 thi 5 record tren mot trang
Note:ban can viet mot vai dong code de de dem tong so record trong datagrid nhe.neu khong se bao loi do
Ho tro :A sang 0128 995 1008
skyearths viết 13:20 ngày 10/10/2018
cũng vậy à. vẫn lỗi đó bạn cho mình yahoo hoặc Gmail để mình send nguyên code bạn test thử. thank nhiều
Cactuslonely viết 13:15 ngày 10/10/2018
Được gửi bởi skyearths
cũng vậy à. vẫn lỗi đó bạn cho mình yahoo hoặc Gmail để mình send nguyên code bạn test thử. thank nhiều
them dong:

if trang="" or trang<=0 then trang=1

them vao sau dong: trang = g("trang") ay! neu ko dc thi minh chiu! ^^

[=========> Bổ sung bài viết <=========]

cactus_foreverlove@yahoo.com
Bài liên quan
0