Dim MaxPage As Integer
'最大行数
Dim RowSum As Integer
'当前页数
Dim CurPage As Integer
'每页显示数量
Dim PageSz as integer
'页面加载
sub page_load(sender as object, e as eventargs)
'页面第一次加载
if Not Page.IsPostBack Then
'声明sql连接
Dim strconn,strsql as string
Dim myconn as oledbconnection
Dim MyDataAdapter as OledbDataAdapter
Dim DS as dataset
'设置数据库连接
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath(ConfigurationSettings.AppSettings("databasepath"))
myconn = new oledbconnection(strconn)
strsql = "SELECT * FROM Message ORDER BY ID DESC"
MyDataAdapter = New OledbDataAdapter(strsql,myconn)
DS = New DataSet()
Try
MyDataAdapter.Fill(ds)
'获取总共有多少行
RowSum = ds.Tables(0).Rows.Count
Catch
RowSum = 0
End Try
Dim PageDS As PagedDataSource = New PagedDataSource
PageDS.DataSource = DS.Tables(0).DefaultView
PageDS.AllowPaging = True
'设置每页显示条数,可以修改。
PageDS.PageSize = 10
PageSz = PageDS.PageSize
'没有指定页数时默认为第一页
If Request.QueryString("Page") <> "" Then
CurPage = Convert.ToInt32(Request.QueryString("Page"))
Else
CurPage = 1
End If
'计算出浏览数据的总页数
If rowSum Mod PageSz > 0 Then
'有余数要加1
MaxPage = RowSum \ PageSz + 1
Else
'正好除尽
MaxPage = RowSum \ PageSz
End If
'设置翻页
PageDS.CurrentPageIndex = CurPage - 1
lblCurrentPage.Text = "共有留言 " & RowSum & " 条,分 " & MaxPage & " 页," & "当前为第 " & CurPage & " 页," & "每页 " & PageSz & " 条"
If Not PageDS.IsFirstPage Then
lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=1"
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & (CurPage - 1)
End If
If Not PageDS.IsLastPage Then
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & (CurPage + 1)
lnklast.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & MaxPage
End If
'数字链接
dim i as integer
for i = CurPage - 5 to CurPage + 5
if CurPage = i then
lblNumber.text & ="<font color=#FF0000><strong>" & CurPage & "</strong></font> "
elseif i <= MaxPage and i >= 1
lblNumber.text & ="<a href='" & Request.CurrentExecutionFilePath & "?Page=" & i &"'>" & i &"</a> "
end if
next
'绑定数据
repmain.DataSource = PageDS
repmain.DataBind()
end if
这个就是我的代码,帮忙帮我看下我还是找不出来.
运行下 还是这个提示
一个自定义分页的问题异常详细信息: System.IndexOutOfRangeException: 无法找到表 0。
源错误:
行 153: End Try
行 154: Dim PageDS As PagedDataSource = New PagedDataSource
行 155: PageDS.DataSource = ds.Tables(0).defaultview
行 156: PageDS.AllowPaging = True
行 157: '设置每页显示条数,可以修改。
总是有这样一句话,请大家帮下我解决下,谢谢大家了