日期:2014-05-17  浏览次数:20432 次

aspx分页中点击下一页时当前页又变成了1
我是用VB语言做的,不过C#也有同样问题。 部分代码如下:
news.aspx页面中:
<asp:Button ID="btnPro" runat="server" Text="上一页" />&nbsp;&nbsp;
<asp:Button ID="btnNext" runat="server" Text="下一页" />

news.aspx.vb中(就是news.aspx页面的后台代码):
  Public pSize As Integer = 3
  Public pIndex As Integer = 1
  Public pCount As Integer

  ''' <summary>
  ''' 加载事件
  ''' </summary>
  ''' <param name="sender"></param>
  ''' <param name="e"></param>
  ''' <remarks></remarks>
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

  If IsPostBack = False Then
  '新闻分页
  Me.rptNews.DataSource = newsService.GetNewsByTIdByPage(1, pSize, pIndex)
  Me.rptNews.DataBind()
  End If

  '求总页数
  Dim newsCount As Integer = newsService.GetNewsCountByTypeId(1)
  pCount = IIf(newsCount Mod pSize = 0, newsCount \ pSize, newsCount \ pSize + 1)

  End Sub

  ''' <summary>
  ''' 下一页按钮单击事件
  ''' </summary>
  ''' <param name="sender"></param>
  ''' <param name="e"></param>
  ''' <remarks></remarks>
  Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNext.Click

  If pIndex < pCount Then
  pIndex = pIndex + 1
  Me.btnPro.Enabled = True
  ElseIf pIndex = pCount Then
  Me.btnNext.Enabled = False
  Me.btnPro.Enabled = True
  End If

  '绑定新闻分页
  Me.rptNews.DataSource = newsService.GetNewsByTIdByPage(1, pSize, pIndex)
  Me.rptNews.DataBind()

  End Sub

  运行程序发现:加载时一切正常,点击下一页时,rptNews中也会变成第二页,但再点,还是第二页...
  调试发现:点击第二页按钮时pIndex(当前页数)又变成了1。怎么解决?谁知道?在线等待......谢谢了。

------解决方案--------------------
发解决方案上来

------解决方案--------------------
祝贺解决 果断领分