As noted, I suggested a Fromview, if you wanted to page each of the 3 (or 4) questions displyed.
I kind of assumed, you want 3 questions, but each could page, so say you display 3 "secitons"
Physics:
Question text
"pager here"
Math:
Math question text"
Pager here
Biology
Question text
Pager here
So, we could display 3 sections, each with a pager.
But, you want say 3 (or 4) questions. For that I would use a repeater, and simple "build" and "cook up" your OWN data paging. This way, you can drop in one repeater - and FEED it ONLY 3 questions.
I don't have sample questions. But, say we drop in a repeater (don't care what you have inside - not important).
So, say we have this markup:
Now, I hid the repeater markup above - (markup in repeater not important here), but NOTE the 2 buttons below - our next, previous.
So, the code to control this now becomes this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Session("PageNumber") = 1 ' start at page 1 of questions
Session("PageSize") = 3 ' number questions per page
LoadData()
End If
End Sub
Sub LoadData()
Using conn As SqlConnection = New SqlConnection(My.Settings.TEST4)
Dim strSQL As String =
"SELECT * FROM tblHotelsA ORDER BY HotelName"
' we change above to this for paging:
strSQL =
"SELECT * FROM tblHotelsA ORDER BY HotelName
OFFSET ((@PageNumber - 1) * @RowspPage) ROWS
FETCH NEXT @RowspPage ROWS ONLY"
Using cmd As SqlCommand = New SqlCommand(strSQL, conn)
cmd.Parameters.Add("@PageNumber", SqlDbType.Int).Value = Session("PageNumber")
cmd.Parameters.Add("@RowspPage", SqlDbType.Int).Value = Session("PageSize")
conn.Open()
Dim rstData As New DataTable
rstData.Load(cmd.ExecuteReader)
Repeater2.DataSource = rstData
Repeater2.DataBind()
End Using
End Using
' deal with next/previous buttons and "info"
Dim intCurrentPage As Integer = Session("PageNumber")
Dim intStart As Integer = ((intCurrentPage - 1) * Session("PageSize")) + 1
Dim intEnd As Integer = intStart + Session("PageSize") - 1
lblNextInfo.Text = "Viewing Questions " & intStart & " to " & intEnd
End Sub
Really, not much more code then just loading up the repeater.
Now, we have to code up our next/previous buttons.
They are quite simple, say like this:
Protected Sub cmdNext_Click(sender As Object, e As EventArgs) Handles cmdNext.Click
Session("PageNumber") += 1
LoadData()
End Sub
Protected Sub cmdPrevious_Click(sender As Object, e As EventArgs) Handles cmdPrevious.Click
Session("PageNumber") -= 1
LoadData()
End Sub
Now, of course you probably on start up get the (query) the total number of questions, and thus could "enable" or hide the next/previous buttons. But, when we run the above, I'll get 3 repeaters like this:
so, really, I would NOT use built in paging, since the issue is this is not a grid or table, and while paging probably COULD work VERY well if you adopted a ListView in this case?
Since you already have a repeater setup, then building your own custom pager code as per above is most likely the path of least efforts. As noted, you have to add to above - since I would "query" and get the total number of questions, and also say if on page 1, then the previous button of course has to be disabled, or a message given that your can't move in that direction anymore. But, the meat and potatoes, and concept of above should work well, and it not really much more code then having to load up the repeater anyway.
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada