也是啊,数据都读出来了,肯定不会再变了,呵呵,但这是为什么呢????
还有点
Public Sub btnPage_Click(ByVal Sender As System.Object, ByVal E As System.EventArgs) Handles btnPage.Click
'下面首先从隐藏标签中读取总页数
If txtPage.Text <> "" Then
Dim intPageCount As Integer = CInt(lblPageCount.Text) '读取总页数
'下面获取客户填写的页码,并处理使其符合要求
Dim intPageIndex As Integer = CInt(txtPage.Text)
If intPageIndex < 1 Then
intPageIndex = 0 '如果客户填写了小于1的页码,则显示首页
ElseIf intPageIndex > intPageCount Then
intPageIndex = intPageCount - 1 '如果填写了大于实际页面的数字,则显示末页
Else
intPageIndex = intPageIndex - 1 '因为索引从0开始,所以减1
End If
txtPage.Text = "" '清空文本框
'下面将要显示的页码保存到隐藏标签中
lblPageIndex.Text = intPageIndex
'下面重新绑定数据
Call class1()
End If
End Sub
谢谢几位的帮助.我从头看了好几遍了,也没看出是哪错了.我现在把代码贴出来,大家帮看一下~~~
对了,忘了说明一点,我是在首页上填写的要搜索的内容和点的搜索按钮.然后转到这页来显示.在这页获取一下首页所填的内容.
Page_load事件:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Page.IsPostBack Then
Dim searchinfo As String = Request.QueryString("info")
'每页显示的个数
Pagesize = 2
'联接数据库
conn.Open()
'计算总共有多少记录
Dim strsql As String = "select count(*) as ID from dvlist where dvname='" & searchinfo & "'"
Dim cmd As New SqlCommand(strsql, conn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
Dim intCount As Integer
If dr.Read() Then
intCount = dr("ID")
Else
intCount = 0
End If
dr.Close()
conn.Close()
lblRecordCount.Text = intCount
RecordNum = intCount
'计算总共有多少页
If RecordNum Mod Pagesize = 0 Then
Pagecount = RecordNum \ Pagesize
Else
Pagecount = RecordNum \ Pagesize + 1
End If
ViewState("PageCount") = Pagecount
If Not IsPostBack Then
CurrentPage = 0
ViewState("PageIndex") = 0
dvlist()
End If
label1.Text = "当前显示的是第 1 页 /"
End If
End Sub
上一页,下一页事件:
Sub Page_OnClick(ByVal sender As Object, ByVal e As CommandEventArgs)
CurrentPage = ViewState("PageIndex")
Pagecount = ViewState("PageCount")
Dim cmd As String = e.CommandName
Select Case cmd
Case "next"
If CurrentPage < (Pagecount - 1) Then CurrentPage += 1
Case "prev"
If CurrentPage > 0 Then CurrentPage -= 1
End Select
ViewState("PageIndex") = CurrentPage
label1.Text = "当前显示的是第 " & CurrentPage + 1 & " 页 " & "/"
dvlist()
End Sub
丢了一点,下面是数据绑定的代码
Sub dvlist()
Dim searchinfo As String = Request.QueryString("info")
Dim StartIndex As Integer
StartIndex = CurrentPage * Pagesize
Dim cmd As New SqlCommand("select * from dvlist where dvname like '%" & searchinfo & "%'", conn)
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New DataSet
adp.Fill(ds, StartIndex, Pagesize, "dvlist")
mydvs.DataSource = ds.Tables("dvlist").DefaultView
mydvs.DataBind()
lbnNextPage.Enabled = True
lbnPrevPage.Enabled = True
If (CurrentPage = (Pagecount - 1)) Then lbnNextPage.Enabled = False
If (CurrentPage = 0) Then lbnPrevPage.Enabled = False
End Sub