M
mosscliffe
I am sorry but I am all very new and slow at understanding all this
ASP.NET2.
I found some code which showed how to page with a repeater. All very
excited as I had been looking for this all day. It worked wonderfully,
but it was in C# So I converted it to VB with
http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx
It got upset about private and so I changed those to protected
My problem is the NEXT Button subroutine gets called twice, but the
PREV one only got called once.
After lots of hair pulling, I eventually worked out that it was because
the PREV button did not have the Handles cmdPrev.Click. I added that
to the PREV Button and now that executes twice. I do not fully
understand this Handles reference, but it is always there if I set up a
default event for a Button.
I don't think it is a postback problem, because the page is only
loading once and I have commented out all other code.
OK so why is / are the Button routines being executed twice.
The code is as follows.
Imports System.data
Partial Class timrepeat
Inherits System.Web.UI.Page
Public Property CurrentPage() As Integer
Get
Dim cpg As Object = Me.ViewState("_CurrentPage")
If cpg Is Nothing Then
Return 0
Else
Return CType(cpg, Integer)
End If
End Get
Set(ByVal value As Integer)
Me.ViewState("_CurrentPage") = value
End Set
End Property
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'ItemsGet()
lbxDebug.Items.Insert(0, "PageLoad:
--->>>>>>>>>>>>>>>>>>>>>>>>>--- Curr Page:" & CurrentPage.ToString)
End Sub
Private Sub ItemsGet()
Dim Items As DataSet = New DataSet
Items.ReadXml(MapPath("Items.xml"))
Dim objPds As PagedDataSource = New PagedDataSource
objPds.DataSource = Items.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 1
objPds.CurrentPageIndex = CurrentPage
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString + "
of " + objPds.PageCount.ToString
cmdPrev.Enabled = Not objPds.IsFirstPage
cmdNext.Enabled = Not objPds.IsLastPage
repeaterItems.DataSource = objPds
repeaterItems.DataBind()
End Sub
Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
lbxDebug.Items.Insert(0, "NEXTBEFORE:CurrentPage= " &
CurrentPage.ToString)
CurrentPage += 1
lbxDebug.Items.Insert(0, "NEXTAFTER:CurrentPage= " &
CurrentPage.ToString)
'ItemsGet()
End Sub
Protected Sub cmdPrev_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdPrev.Click
lbxDebug.Items.Insert(0, "PREVBEFORE:CurrentPage= " &
CurrentPage.ToString)
CurrentPage -= 1
lbxDebug.Items.Insert(0, "PREVAFTER:CurrentPage= " &
CurrentPage.ToString)
'ItemsGet()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
End Sub
End Class
The aspx page is
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="timrepeat.aspx.vb" Inherits="timrepeat" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%--<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
--%>
<html>
<head>
<title>TestRepeater</title>
</head>
<body>
<form id="frmTest" method="post" runat="server">
<table width="100%" border="0">
<tr>
<td> Repeater control with Paging functionality</td>
</tr>
<tr>
<td> <asp:label id="lblCurrentPage"
runat="server"></asp:label></td>
</tr>
<tr>
<td> <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>
</table>
<table border="1">
<asp:repeater id="repeaterItems" runat="server">
<itemtemplate>
<tr>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemName") %></b></td>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemDescription") %></b></td>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemPrice") %></b></td>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemInStock") %></b></td>
</tr>
</itemtemplate>
</asp:repeater>
</table>
<asp:ListBox ID="lbxDebug" runat="server"
Rows="10"></asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
ASP.NET2.
I found some code which showed how to page with a repeater. All very
excited as I had been looking for this all day. It worked wonderfully,
but it was in C# So I converted it to VB with
http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx
It got upset about private and so I changed those to protected
My problem is the NEXT Button subroutine gets called twice, but the
PREV one only got called once.
After lots of hair pulling, I eventually worked out that it was because
the PREV button did not have the Handles cmdPrev.Click. I added that
to the PREV Button and now that executes twice. I do not fully
understand this Handles reference, but it is always there if I set up a
default event for a Button.
I don't think it is a postback problem, because the page is only
loading once and I have commented out all other code.
OK so why is / are the Button routines being executed twice.
The code is as follows.
Imports System.data
Partial Class timrepeat
Inherits System.Web.UI.Page
Public Property CurrentPage() As Integer
Get
Dim cpg As Object = Me.ViewState("_CurrentPage")
If cpg Is Nothing Then
Return 0
Else
Return CType(cpg, Integer)
End If
End Get
Set(ByVal value As Integer)
Me.ViewState("_CurrentPage") = value
End Set
End Property
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'ItemsGet()
lbxDebug.Items.Insert(0, "PageLoad:
--->>>>>>>>>>>>>>>>>>>>>>>>>--- Curr Page:" & CurrentPage.ToString)
End Sub
Private Sub ItemsGet()
Dim Items As DataSet = New DataSet
Items.ReadXml(MapPath("Items.xml"))
Dim objPds As PagedDataSource = New PagedDataSource
objPds.DataSource = Items.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 1
objPds.CurrentPageIndex = CurrentPage
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString + "
of " + objPds.PageCount.ToString
cmdPrev.Enabled = Not objPds.IsFirstPage
cmdNext.Enabled = Not objPds.IsLastPage
repeaterItems.DataSource = objPds
repeaterItems.DataBind()
End Sub
Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
lbxDebug.Items.Insert(0, "NEXTBEFORE:CurrentPage= " &
CurrentPage.ToString)
CurrentPage += 1
lbxDebug.Items.Insert(0, "NEXTAFTER:CurrentPage= " &
CurrentPage.ToString)
'ItemsGet()
End Sub
Protected Sub cmdPrev_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdPrev.Click
lbxDebug.Items.Insert(0, "PREVBEFORE:CurrentPage= " &
CurrentPage.ToString)
CurrentPage -= 1
lbxDebug.Items.Insert(0, "PREVAFTER:CurrentPage= " &
CurrentPage.ToString)
'ItemsGet()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
End Sub
End Class
The aspx page is
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="timrepeat.aspx.vb" Inherits="timrepeat" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%--<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
--%>
<html>
<head>
<title>TestRepeater</title>
</head>
<body>
<form id="frmTest" method="post" runat="server">
<table width="100%" border="0">
<tr>
<td> Repeater control with Paging functionality</td>
</tr>
<tr>
<td> <asp:label id="lblCurrentPage"
runat="server"></asp:label></td>
</tr>
<tr>
<td> <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>
</table>
<table border="1">
<asp:repeater id="repeaterItems" runat="server">
<itemtemplate>
<tr>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemName") %></b></td>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemDescription") %></b></td>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemPrice") %></b></td>
<td> <b><%# DataBinder.Eval(Container.DataItem,
"ItemInStock") %></b></td>
</tr>
</itemtemplate>
</asp:repeater>
</table>
<asp:ListBox ID="lbxDebug" runat="server"
Rows="10"></asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>