按照孟子E章中的代码终于在DATALIST中分出了页(其它方法也参照过,不过我学习用的是ASP.NET+ACCESS+VB,VB一定要全代码分离.所以花了很多时间将网上找的代码一一改出来都不理想).但是新的问题出来了,在此请教老鸟们.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lie As Integer = Request.QueryString("sel")
Dim newid As String = Request.QueryString("classid")
Dim tex As String = Session("namestr")
Session.Remove("namestr")
Dim strsql As String
Dim objconn As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("database/movie.mdb"))
objconn.Open()
Dim objCommand As OleDbDataAdapter
Dim ds As New DataSet
If lie = 1 Then
strsql = "select * from movie where category='" & newid & "'"
Else
strsql = "select * from movie where name like '%" & tex & "%'"
End If
objCommand = New OleDbDataAdapter(strsql, objconn)
问题就在这里:我要通过Request.QueryString("sel")传到本页的值来判断具体执行哪个字符串,但是这就与lnkPrev.NavigateUrl 和lnkNext.NavigateUrl 有冲突,if not ispostback then 判断,你会发现加在哪里都不合适.
我不知道怎么解决这个问题,求求高手了.如果要我看别的文章,请告诉我VB的实例.
objCommand.Fill(ds, "movie")
Dim objPds As PagedDataSource = New PagedDataSource()
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 6
Dim CurPage As Integer
If Not (Request.QueryString("Page") Is Nothing) Then
CurPage = Convert.ToInt32(Request.QueryString("Page"))
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
lblCurrentPage.Text = "当前页:" + CurPage.ToString()
If Not objPds.IsFirstPage Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1)
End If
If Not objPds.IsLastPage Then
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1)
End If
pagenum.Text = "共" & objPds.PageCount.ToString & "页"
objconn.Close()
DataList1.DataSource = objPds
DataList1.DataBind()
End Sub