Admittedly it took me some time to absorb VSEW 2012 and EF (and Iâm still a little wobbly), but I feel that although Iâm adding more sophisticated code, the problems seem to be multiplying. I feel Iâm missing something fundamental here.
I do mean that Iâm at fault here, not the suggestions Iâve received from you and others so far.
At its most basic, hereâs the relevant mark-up (all other lines removed). Conceptually Iâm retrieving the data from one SQL Server table into a local table and binding it to the ListView during a non-pageback Page_Load subroutine.
<script type="text/vb" runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Me.MaintainScrollPositionOnPostBack = "True"
If Not Page.IsPostBack Then
Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim MyDataTable As DataTable
Dim MyReader As SqlDataReader
MyConnection = New SqlConnection()
MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
MyCommand = New SqlCommand()
MyCommand.CommandText = "SELECT [HTMLSrc],[HTMLTitle] FROM [BusinessAdverts] " & _
"WHERE [ValidFrom] <= GETDATE() AND " & _
"[ValidTo] >= GETDATE()" & _
"ORDER BY NEWID()"
MyCommand.CommandType = CommandType.Text
MyCommand.Connection = MyConnection
MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)
MyDataTable = New DataTable()
' Loading DataTable using a DataReader
lvAdverts.DataSource = MyDataTable
<p>No adverts to show at the moment</p>
<asp:Label id="HTMLtext" runat="server" Text='<%# "<div><a href=""images/" + Eval("HTMLSrc") + "_banner.jpg""><img src=""images/" + Eval("HTMLSrc") + "_banner_thumb.jpg"" alt="""" title=""" + Eval("HTMLTitle") + """ /></a></div>"%>' />
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
<asp:DataPager runat="server" id="DataPager1" PageSize="3" PagedControlID="lvAdverts">
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
The effect is that the first three adverts (cut down to 3 to make testing and changing faster) with four buttons â First Previous, Next and Last. The first two are greyed-out, while the next two are active.
However, clicking on the Next button appears to do nothing. The same 3 adverts show and the buttons retain their greyed-out/active status.
Clicking again on the Next button makes a small change. The same 3 adverts show but all the buttons are now active. Remember there are about 60 adverts in total.
Actually clicking on any active buttons makes no difference to the adverts shown.
I trawled the ânet and came across some advice on re-binding the table to the control and tried this, but I had difficulty accessing the table as it had moved out of scope (disposed in the non-pageback Page_Load sub).
As I say, while I have gone further and set up EF solutions, the result is essentially the same.
To be honest Iâve left this alone for a week or so as it was doing my head in.
Before I try again, can you say why this most basic approach fails and what EF offers to solve it â to my mind EFâs strength is conceptually decoupling the actual database (SQL Server or whatever) from the code. I donât see how it changes the nature of the persistent âtemporaryâ table extracted from the SQL Server DB and used to page back and forth in the ListView using the DataPager.
I know this may come across as personal. It is not. I honestly feel Iâm missing the point here and felt it would be best to explain what Iâve tried, what the effects are and where the holes in my knowledge are.
Help me Obi-Wan Kenobi â youâre my only hope!