也是啊,数据都读出来了,肯定不会再变了,呵呵,但这是为什么呢????
谢谢几位的帮助.我从头看了好几遍了,也没看出是哪错了.我现在把代码贴出来,大家帮看一下~~~
对了,忘了说明一点,我是在首页上填写的要搜索的内容和点的搜索按钮.然后转到这页来显示.在这页获取一下首页所填的内容.
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