31
ASP'de sayfalama yapımı Paging
0 Comments | admin tarafından yazıldı, kategori: ASP örnek kodlar, Uygulamalar
Sitenizde sayfalama yapmak için kullanabileceÄŸiniz fonksiyon. Ürünler tablonuzdan çekeceÄŸiniz ürün fotoÄŸrafı ve ürün adını 6′ÅŸarlı olarak listelemek istiyorsunuz. İlk altı ürün görüntülendikten sonra sayfanın altında sayfalama(paging, pagination) seçeneklerinin görüntülenmesini istiyoruz.
Yazdığımız Paging() fonksiyonunu çağırmanız durumunda bunu gerçekleÅŸtirebilirsiniz. Kendi veritabanınızdaki deÄŸerlere göre deÄŸiÅŸtirmeniz gereken yerler yanlarında belirtilmiÅŸtir. AÅŸağıdaki kodları kopyalayıp bir .asp dosyası içine yapıştırıp çalıştırabilirsiniz. Alt kısımdaki stil dosyası verilmiÅŸtir, sayfanızın head kısmına ekleyebilirsiniz. currentpage class’ı ile seçilen sayfanın farklı görüntülenmesi saÄŸlanmıştır.
<%function Paging()
dim SQL
dim Mycon1
dim Myset1
dim currentpage(1000)
dim i,j,viewcount,page,maxcount
adoopen_connection mycon1 ' Veritabanı bağlantısını aç, değiştir
SQL="select * from PRODUCTS order by pid desc"Â ' PRODUCTS ve pid deÄŸiÅŸtir
adoopen_fwdonly myset1,sql,mycon1 ' Verileri myset1 kayıt kümesine yükle
i=0
viewcount=6 ' Görüntülenecek öğe sayısı, değiştirilebilir
page=Request("page")*1
maxcount=page*viewcount
if maxcount=0 or maxcount="" then
maxcount=viewcount
page=1
end if
currentpage(page)="class='currentpage'"
temp = temp & "<table cellpadding='2' cellspacing='2' width='100%'>"
do while not myset1.eof
if (i>=maxcount-viewcount) and (i<maxcount) then
' -- ÜRÜN LİSTELEME BAŞLA--
'3erli sütunlarla ürünleri listeliyoruz
if (i mod 3=0) then
temp = temp & "<tr>"
end if
temp = temp & "<td>"
temp = temp & "<img src='"& myset1.fields("urunfoto") &"' border='0'>"Â 'urunfoto field deÄŸiÅŸebilir
temp = temp & "Â Â Â <br><b>" & myset1.fields("urunadi") & "</b>" 'urunadi deÄŸiÅŸebilir
temp = temp & "Â Â Â </td>"
if (i mod 3=2) then
temp = temp & "</tr>"
end if
' -- ÜRÜN LİSTELEME SONU--
end if
i=i+1
myset1.movenext
loop
mycon1.close
temp = temp & "</table>"
' -- SAYFALAMA BAÅžLA -- temp = temp & "<div class='pagination'>" temp = temp & "<ul>"
if i<>0 and page<>"" and page<>1 and page<>0 then temp = temp & "   <li><a class='prevnext' href='urunler.asp?page="& page-1 &"'>« Geri</a></li>" end if for j=1 to i/viewcount+1 temp = temp & "<li><a "& currentpage(j) &" href='urunler.asp?page="& j &"'>"& j &"</a></li>" next response.write "--"& i/viewcount & "--" if (i/viewcount>page) then temp = temp & "<li><a class='prevnext' href='urunler.asp?page="& page+1 &"'>İleri »</a></li>" end if temp = temp & "</ul></div>"
' -- SAYFALAMA SONU --
set mycon1 = nothing ' Veri tabanını kapat set myset1 = nothing ' Recordseti kapat Paging= temp ' temp ile oluşturduğumuz sonuçları geri gönder end function %>
Stil dosyası:
<style type="text/css">
.pagination{
padding: 2px;
margin: 1em 0;
clear: both;
}
.pagination ul{
margin: 0;
padding: 0;
text-align: right; /*Set to "left" or "right" to left/right align pagination interface*/
font-size: 100%;
}
.pagination li{
list-style-type: none;
display: inline;
padding-bottom: 1px;
}
*:first-child+html .pagination li a{ /*IE7 only CSS hack*/
margin-right: 4px; /*IE bug */
}
* html .pagination li a{ /*IE6 and below CSS */
margin-right: 4px; /*IE bug */
}
.pagination a, .pagination a:visited, .pagination a:active{
padding: 0 5px;
border: 1px solid #9aafe5;
text-decoration: none;
color: #2e6ab1;
}
.pagination a:hover{
border: 1px solid #2b66a5;
color: #000;
background-color: #FFFF80;
}
.pagination a.currentpage{ /*Style for currently selected page link*/
background-color: #2e6ab1;
color: #FFF !important;
border-color: #2b66a5;
font-weight: bold;
cursor: default;
}
.pagination a.prevnext{ /*Style for previous and next link*/
font-weight: bold;
}
</style>

