我有一个带有DataPager和计时器的Listview控件,可以每秒钟自动前进一页Listview。
问题是Listview跳转了2页...
Protected Sub timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer.Tick
'Verify that the session variable is not null
If Session("startRowIndex") Is Nothing Then
Session.Add("startRowIndex", 0)
End If
'Create a variable to store the first record to show
Dim startRowIndex As Integer = Convert.ToInt32(Session("startRowIndex"))
'Increase the first record to display in the size of the page
startRowIndex = startRowIndex + Me.DataPager1.MaximumRows
'Show from the first record to the size of the page
Me.DataPager1.SetPageProperties(startRowIndex, Me.DataPager1.MaximumRows, True)
'If the first record exceeds the total number of records, restart the count.
If startRowIndex > Me.DataPager1.TotalRowCount Then
startRowIndex = 0
End If
Session("startRowIndex") = startRowIndex
End SubDataPager控件...
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="1" >
<Fields>
<asp:NextPreviousPagerField ButtonType="Button"
ShowFirstPageButton="True"
ShowNextPageButton="False"
ShowPreviousPageButton="True" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Button"
ShowLastPageButton="True"
ShowNextPageButton="true"
ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>时间控制。
<asp Timer ID="timer" runat="server" Interval="1000" OnTick="timer_Tick">
</asp Timer>我是不是漏掉了什么简单的东西?
发布于 2014-01-04 16:31:06
在设置页面属性之前,您正在增加strartrowindex,这是错误的。它应该是:
*编辑:*请记住,RowIndex以0为基数,且count始终为LastRowIndex + 1,您需要从MaximumRows中减去1。
'Show from the first record to the size of the page
Me.DataPager1.SetPageProperties(startRowIndex, Me.DataPager1.MaximumRows, True)
'Increase the first record to display in the size of the page
startRowIndex = startRowIndex + Me.DataPager1.MaximumRows -1https://stackoverflow.com/questions/20913056
复制相似问题