have this code that worked fine until i tried to put custom paging in it. I'm getting an error that says "Cannot compute Count for a data source that does not implement ICollection". I read that you cant use a datareader but i'm using a table adapter so what's my issue. Any help would be appreciated.
<%@ Page Language="VB"%>
<script runat="server">
Private _CurrentPage As Integer
Public Property CurrentPage() As Integer
Get
'look for current page in ViewState
_CurrentPage = CInt(ViewState("CurrentPage"))
Return _CurrentPage
End Get
Set(ByVal Value As Integer)
viewstate("CurrentPage") = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindData()
End Sub
Sub BindData()
Dim recipeAdapter As New PublicWebDMZTableAdapters.webRecipeRatingsTableAdapter
Dim dsPaged As New PagedDataSource()
dsPaged.DataSource = recipeAdapter.GetDataByRecipeID(340)
dsPaged.AllowPaging = True
dsPaged.PageSize = 5
dsPaged.CurrentPageIndex = CurrentPage
'Disable Prev or Next buttons if necessary
cmdPrev.Enabled = Not dsPaged.IsFirstPage
cmdNext.Enabled = Not dsPaged.IsLastPage
CommentRepeater.DataSource = dsPaged
CommentRepeater.DataBind()
'Dispose Items
recipeAdapter.Dispose()
End Sub
Sub cmdPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Set viewstate variable to the previous page
CurrentPage -= 1
' Reload control
BindData()
End Sub
Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Set viewstate variable to the previous page
CurrentPage += 1
' Reload control
BindData()
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns=" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="checkbox_form" runat="server">
<asp:Repeater ID="CommentRepeater" runat="server">
<ItemTemplate>
<table width="423" border="0" style="table-layout:fixed;word-wrap:break-word;">
<tr>
<td style="font-size:12.8px"><b><%#Eval("commentSubject")%></b></td>
</tr>
<tr>
<td style="font-size:11.5px;"><b><%#String.Format("{0:d}", Eval("ratedon"))%> at <%#String.Format("{0:t}", Eval("ratedon")).ToLower%></b></td>
</tr>
<tr>
<td valign="top"><b>Cook:</b> <i><%# Eval("displayUserName") %></i>
<b>User Rating: <img src="/PublicSite/images/rate<%# Eval("rating") %>0.gif" width="65" height="13" /></b></td>
</tr>
<tr>
<td><br /><%#Eval("comment")%></td>
</tr>
<tr>
<td> </td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td style="color:#00387F">....................................................................................................................................</b></td>
</tr>
<tr>
<td> </td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<tr>
<td class="cbox" align="right" valign="bottom" style="font-size:11px;font-weight:bolder">
<asp:button id="cmdPrev" runat="server" text="Prev" onclick="cmdPrev_Click"></asp:button>
<asp:button id="cmdNext" runat="server" text="Next" onclick="cmdNext_Click"></asp:button>
</td>
</tr>
</form>
</body>
</html>
<%@ Page Language="VB"%>
<script runat="server">
Private _CurrentPage As Integer
Public Property CurrentPage() As Integer
Get
'look for current page in ViewState
_CurrentPage = CInt(ViewState("CurrentPage"))
Return _CurrentPage
End Get
Set(ByVal Value As Integer)
viewstate("CurrentPage") = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindData()
End Sub
Sub BindData()
Dim recipeAdapter As New PublicWebDMZTableAdapters.webRecipeRatingsTableAdapter
Dim dsPaged As New PagedDataSource()
dsPaged.DataSource = recipeAdapter.GetDataByRecipeID(340)
dsPaged.AllowPaging = True
dsPaged.PageSize = 5
dsPaged.CurrentPageIndex = CurrentPage
'Disable Prev or Next buttons if necessary
cmdPrev.Enabled = Not dsPaged.IsFirstPage
cmdNext.Enabled = Not dsPaged.IsLastPage
CommentRepeater.DataSource = dsPaged
CommentRepeater.DataBind()
'Dispose Items
recipeAdapter.Dispose()
End Sub
Sub cmdPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Set viewstate variable to the previous page
CurrentPage -= 1
' Reload control
BindData()
End Sub
Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Set viewstate variable to the previous page
CurrentPage += 1
' Reload control
BindData()
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns=" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="checkbox_form" runat="server">
<asp:Repeater ID="CommentRepeater" runat="server">
<ItemTemplate>
<table width="423" border="0" style="table-layout:fixed;word-wrap:break-word;">
<tr>
<td style="font-size:12.8px"><b><%#Eval("commentSubject")%></b></td>
</tr>
<tr>
<td style="font-size:11.5px;"><b><%#String.Format("{0:d}", Eval("ratedon"))%> at <%#String.Format("{0:t}", Eval("ratedon")).ToLower%></b></td>
</tr>
<tr>
<td valign="top"><b>Cook:</b> <i><%# Eval("displayUserName") %></i>
<b>User Rating: <img src="/PublicSite/images/rate<%# Eval("rating") %>0.gif" width="65" height="13" /></b></td>
</tr>
<tr>
<td><br /><%#Eval("comment")%></td>
</tr>
<tr>
<td> </td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td style="color:#00387F">....................................................................................................................................</b></td>
</tr>
<tr>
<td> </td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<tr>
<td class="cbox" align="right" valign="bottom" style="font-size:11px;font-weight:bolder">
<asp:button id="cmdPrev" runat="server" text="Prev" onclick="cmdPrev_Click"></asp:button>
<asp:button id="cmdNext" runat="server" text="Next" onclick="cmdNext_Click"></asp:button>
</td>
</tr>
</form>
</body>
</html>