我正在使用asp:repeater通過VB.NET代碼隱藏文件完成分頁的ASP.NET網站。雖然我在數據庫連接時遇到了問題。據我所知,分頁正在工作,但我無法確定數據。ASP.NET OleDbConnection問題
該數據庫是Microsoft Access數據庫。應該訪問數據庫的功能是:
Dim pagedData As New PagedDataSource
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
doPaging()
End Sub
Function getTheData() As DataTable
Dim DS As New DataSet()
Dim strConnect As New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=App_Data/ArtDatabase.mdb")
Dim objOleDBAdapter As New OleDbDataAdapter("SELECT ArtID, FileLocation, Title, UserName, ArtDate FROM Art ORDER BY Art.ArtDate DESC", strConnect)
objOleDBAdapter.Fill(DS, "Art")
Return DS.Tables("Art").Copy
End Function
Sub doPaging()
pagedData.DataSource = getTheData().DefaultView
pagedData.AllowPaging = True
pagedData.PageSize = 2
Try
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try
btnPrev.Visible = (Not pagedData.IsFirstPage)
btnNext.Visible = (Not pagedData.IsLastPage)
pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
ArtRepeater.DataSource = pagedData
ArtRepeater.DataBind()
End Sub
的ASP.NET是:
<asp:Repeater ID="ArtRepeater" runat="server">
<HeaderTemplate>
<h2>Items in Selected Category:</h2>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink runat="server" ID="HyperLink"
NavigateUrl='<%# Eval("ArtID", "ArtPiece.aspx?ArtID={0}") %>'>
<img src="<%# Eval("FileLocation") %>"
alt="<%# DataBinder.Eval(Container.DataItem, "Title") %>t"/> <br />
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</asp:HyperLink>
</li>
</ItemTemplate>
</asp:Repeater>
嗨馬特你得到一個錯誤或沒有出現什麼? 你可以嘗試使用autogenerate = true綁定到datagrid,看看返回的是什麼 – alexmac 2008-10-12 09:49:24
我沒有收到錯誤,只是沒有出現。 – Matt 2008-10-13 12:29:44
如果我給中繼器一個DataSourceID =「AccessDataSource1」,它會很好地提取數據,但它不支持我需要的分頁。 – Matt 2008-10-13 12:35:04