G
Guest
Hello, i'm working on a greeting card website, there is a page where i'm
showing
greeting cards, i have done paging on this page with using Datalist and its
working well but i have a problem is on Next button i want to disable Next
button link when user is on last page so pls tell me how can i do it in
ASP.NET, below i'm giving my page code,pls review it.
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.Data.oledb" %>
<html>
<head>
<title>Paging in Datalist - by Das</title>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack() Then
intPageSize.Text = "5"
intCurrIndex.Text = "0"
DataBind()
End If
End Sub
Private Sub DataBind()
Dim cs,d,q2 as string
Dim c,rc,i as integer
c=Request.QueryString("catID")
'Response.Write(c)
q2="Select count(*) from cards where categoryID=Cint('"& c &"') "
Dim pics as Arraylist=new Arraylist()
cs=System.configuration.ConfigurationSettings.Appsettings("connstr")
Dim objconn as new oledbConnection(cs)
Dim objcomm as new oledbCommand(q2,objconn)
objconn.open()
rc=objcomm.Executescalar()
'Response.Write(rc)
Dim objDA As New oledbdataAdapter("Select * from cards where
categoryID=Cint('"& c &"')", objConn)
Dim objDS As New DataSet()
objDA.Fill(objDS)
intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
objDS = Nothing
objDS = New DataSet()
objDA.Fill (objDS, Cint(intCurrIndex.Text), CInt(intPageSize.Text), "cards")
Dim objtable as new DataTable
Dim objrow as DataRow
objtable=objDS.Tables("cards")
for i=0 to 4
objrow=objTable.rows(i)
d="<a href=form.asp?cid=" & objrow("cardID") & ">"& _
"<img src='Friendship/"& objrow("cardthumbnail") &"' border=0></a>"
pics.Add(d)
Next
dList.Datasource=pics
dList.DataBind()
objConn.Close()
PrintStatus()
End Sub
Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = "0"
DataBind()
End Sub
Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = Cstr(Cint(intCurrIndex.Text) - CInt(intPageSize.Text))
If CInt(intCurrIndex.Text) < 0 Then
intCurrIndex.Text = "0"
End If
DataBind()
End Sub
Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
End If
DataBind()
End Sub
Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
Dim tmpInt as Integer
tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
If tmpInt > 0 Then
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - tmpInt)
Else
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
End If
DataBind()
End Sub
Private Sub PrintStatus()
lblStatus.Text = "Total Records:<b>" & intRecordCount.Text
lblStatus.Text += "</b> - Showing Page:<b> "
lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) /
CInt(intPageSize.Text)+1))
lblStatus.Text += "</b> of <b>"
If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) /
CInt(intPageSize.Text)+1))
Else
lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
End If
lblStatus.Text += "</b>"
End Sub
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h2 align="center"><font face="verdana">Paging in DataList</font></h2>
<aspataList ID="dList" Runat="server" Width="100%" RepeatColumns="3"
BorderWidth="1" EnableViewState="False">
<ItemTemplate>
<%# Container.DataItem%>
</ItemTemplate>
</aspataList>
<table width=100% align="right">
<tr>
<td width=76% align=left> <asp:label ID="lblStatus"
Runat="server"
Font-Name="verdana"
Font-Size="10pt" /> </td>
<td width=6%> <font size="2"><a href="datalistpaging.aspx#this"
ID="hrefFirst"
onserverclick="ShowFirst"
runat="server">First</a> </font></td>
<td width=6%> <font size="2"><a href="datalistpaging.aspx#this"
ID="hrefPrevious"
onserverclick="ShowPrevious"
runat="server">Prev</a> </font></td>
<td width=6%>
<a href="datalistpaging.aspx#this" ID="hrefNext" onserverclick="ShowNext"
runat="server">
<font size="2">NEXT</font></a> </td>
<td width=6%> <font size="2">
<a href="datalistpaging.aspx#this"
ID="hrefLast"
onserverclick="ShowLast"
runat="server">Last</a> </font></td>
</tr>
</table>
<asp:label ID="intCurrIndex"
Visible="False"
Runat="server" />
<asp:label ID="intPageSize"
Visible="False"
Runat="server" />
<asp:label ID="intRecordCount"
Visible="False"
Runat="server" />
</form>
</body>
</html>
showing
greeting cards, i have done paging on this page with using Datalist and its
working well but i have a problem is on Next button i want to disable Next
button link when user is on last page so pls tell me how can i do it in
ASP.NET, below i'm giving my page code,pls review it.
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.Data.oledb" %>
<html>
<head>
<title>Paging in Datalist - by Das</title>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack() Then
intPageSize.Text = "5"
intCurrIndex.Text = "0"
DataBind()
End If
End Sub
Private Sub DataBind()
Dim cs,d,q2 as string
Dim c,rc,i as integer
c=Request.QueryString("catID")
'Response.Write(c)
q2="Select count(*) from cards where categoryID=Cint('"& c &"') "
Dim pics as Arraylist=new Arraylist()
cs=System.configuration.ConfigurationSettings.Appsettings("connstr")
Dim objconn as new oledbConnection(cs)
Dim objcomm as new oledbCommand(q2,objconn)
objconn.open()
rc=objcomm.Executescalar()
'Response.Write(rc)
Dim objDA As New oledbdataAdapter("Select * from cards where
categoryID=Cint('"& c &"')", objConn)
Dim objDS As New DataSet()
objDA.Fill(objDS)
intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
objDS = Nothing
objDS = New DataSet()
objDA.Fill (objDS, Cint(intCurrIndex.Text), CInt(intPageSize.Text), "cards")
Dim objtable as new DataTable
Dim objrow as DataRow
objtable=objDS.Tables("cards")
for i=0 to 4
objrow=objTable.rows(i)
d="<a href=form.asp?cid=" & objrow("cardID") & ">"& _
"<img src='Friendship/"& objrow("cardthumbnail") &"' border=0></a>"
pics.Add(d)
Next
dList.Datasource=pics
dList.DataBind()
objConn.Close()
PrintStatus()
End Sub
Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = "0"
DataBind()
End Sub
Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = Cstr(Cint(intCurrIndex.Text) - CInt(intPageSize.Text))
If CInt(intCurrIndex.Text) < 0 Then
intCurrIndex.Text = "0"
End If
DataBind()
End Sub
Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
End If
DataBind()
End Sub
Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
Dim tmpInt as Integer
tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
If tmpInt > 0 Then
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - tmpInt)
Else
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
End If
DataBind()
End Sub
Private Sub PrintStatus()
lblStatus.Text = "Total Records:<b>" & intRecordCount.Text
lblStatus.Text += "</b> - Showing Page:<b> "
lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) /
CInt(intPageSize.Text)+1))
lblStatus.Text += "</b> of <b>"
If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) /
CInt(intPageSize.Text)+1))
Else
lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
End If
lblStatus.Text += "</b>"
End Sub
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h2 align="center"><font face="verdana">Paging in DataList</font></h2>
<aspataList ID="dList" Runat="server" Width="100%" RepeatColumns="3"
BorderWidth="1" EnableViewState="False">
<ItemTemplate>
<%# Container.DataItem%>
</ItemTemplate>
</aspataList>
<table width=100% align="right">
<tr>
<td width=76% align=left> <asp:label ID="lblStatus"
Runat="server"
Font-Name="verdana"
Font-Size="10pt" /> </td>
<td width=6%> <font size="2"><a href="datalistpaging.aspx#this"
ID="hrefFirst"
onserverclick="ShowFirst"
runat="server">First</a> </font></td>
<td width=6%> <font size="2"><a href="datalistpaging.aspx#this"
ID="hrefPrevious"
onserverclick="ShowPrevious"
runat="server">Prev</a> </font></td>
<td width=6%>
<a href="datalistpaging.aspx#this" ID="hrefNext" onserverclick="ShowNext"
runat="server">
<font size="2">NEXT</font></a> </td>
<td width=6%> <font size="2">
<a href="datalistpaging.aspx#this"
ID="hrefLast"
onserverclick="ShowLast"
runat="server">Last</a> </font></td>
</tr>
</table>
<asp:label ID="intCurrIndex"
Visible="False"
Runat="server" />
<asp:label ID="intPageSize"
Visible="False"
Runat="server" />
<asp:label ID="intRecordCount"
Visible="False"
Runat="server" />
</form>
</body>
</html>