Asp.net İle Sayfalama (Veri Türü SQL) (tr
Dosya adımız Sayfala.aspx kodumuz şöyle;
////////////////Sayfala.aspx//////////////////
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<script language="VB" runat="server">
Public objCon As New SQLConnection("server=ASP;User id=SA;password=;database=Northwind"
Sub Sayfa_Load(Source as Object, E as EventArgs)
dim currentSayfa as integer
if request.querystring("Sayfa"
= "" then
currentSayfa = 1
else
currentSayfa = request.querystring("Sayfa"
end if
getRst(currentSayfa)
getSayfala(currentSayfa)
end sub
public sub getRst(Sayfa as integer)
dim SayfaNo as integer
dim sql as string
SayfaNo = 10 * (Sayfa - 1)
Dim ds as DataSet=New DataSet()
sql = "select * from Products"
Dim cmd As SQLDataAdapter = New SQLDataAdapter(sql, objCon)
cmd.Fill(ds, SayfaNo , 10, "results"
rst_table.DataSource = ds.Tables("results"
.DefaultView
rst_table.databind()
end sub
Sub getSayfala(cSayfa as integer)
Dim cmd As SQLCommand = New SQLCommand("Select count(*) from Products", objCon)
objCon.Open()
Dim totalRecords as integer = cmd.ExecuteScalar().toString
Dim totalSayfas As integer
if totalRecords MOD 10 = 0 then
totalSayfas = int(totalRecords / 10)
else
totalSayfas = int(totalRecords / 10) + 1
end if
Dim i as integer
Dim SayfaTxt As String = "More Sayfas : "
if cSayfa > 1 then
SayfaTxt += "<a href=Sayfala.aspx?Sayfa=" & cSayfa - 1 & ">Önceki</a> "
end if
for i = 1 to totalSayfas
if cSayfa = i then
SayfaTxt += "<b>" & i & "</b> "
else
SayfaTxt += "<a href=Sayfala.aspx?Sayfa=" & i & ">" & i & "</a> "
end if
next i
if cSayfa < totalSayfas then
SayfaTxt += "<a href=Sayfala.aspx?Sayfa=" & cSayfa + 1 & ">Sonraki</a> "
end if
showSayfas.text = SayfaTxt
end sub
</script>
<html>
<body>
<asp
ataGrid runat="server" Id="rst_table" cellpadding="0" cellspacing="2" width="96%" font-size = "10pt" RepeatColumns="1" />
<asp:label id="showSayfas" runat="server" Font-Names="Verdana" Font-size="12px" />
</body>
</html>