首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Listview一次前进两页,而不是在timer控件中设置的一页

Listview一次前进两页,而不是在timer控件中设置的一页
EN

Stack Overflow用户
提问于 2014-01-04 05:32:30
回答 1查看 188关注 0票数 0

我有一个带有DataPager和计时器的Listview控件,可以每秒钟自动前进一页Listview。

问题是Listview跳转了2页...

代码语言:javascript
运行
复制
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 Sub

DataPager控件...

代码语言:javascript
运行
复制
 <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>

时间控制。

代码语言:javascript
运行
复制
<asp Timer ID="timer" runat="server" Interval="1000" OnTick="timer_Tick">
</asp Timer>

我是不是漏掉了什么简单的东西?

EN

回答 1

Stack Overflow用户

发布于 2014-01-04 16:31:06

在设置页面属性之前,您正在增加strartrowindex,这是错误的。它应该是:

*编辑:*请记住,RowIndex以0为基数,且count始终为LastRowIndex + 1,您需要从MaximumRows中减去1。

代码语言:javascript
运行
复制
'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 -1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20913056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档