I read and tried to use the repeater paging method I found on 4 Guys from
Rolla (I've tried others also) but it doesn't seem to work. Please see the
code I have below and tell me what I may be doing wrong. I'm using Visual
Studio with SQL 2000. This is question/answer page that loads questions &
answers dynamically. I would like to present 1 question at a time instead of
all questions on one page as quizzes may have up to 50 questions. Can any
one help????
Imports System.Data.OleDb
Imports System.Data
Public Property CurrentPage() As Integer
Get
' look for current page in ViewState
Dim o As Object = Me.ViewState("_CurrentPage")
If o Is Nothing Then
Return 0 ' default to showing the first page
End If
End Get
Set(ByVal Value As Integer)
Me.ViewState("_CurrentPage") = value
End Set
End Property
Private Sub ItemsGet()
' Read sample item info from XML document into a DataSet
Dim Items As New DataSet
Dim DBCommand As OleDbDataAdapter
Dim DBConn As OleDbConnection
Dim objPds As New PagedDataSource
Dim I As Integer
Dim J As Integer
Dim TempID As String
'Connection string goes here.
DBCommand = New OleDbDataAdapter _
("Select SectionQuestionID, QuestionText " _
& "From SectionQuestions Where CourseSectionID = " _
& Session("CourseSectionID"), DBConn)
DBCommand.Fill(Items, "QuizQuestions")
---->Problem 1:
'Data container loads selection from above query ("QuestionText") but not for
the other query on this page.
'Loads questions
For I = 0 To Items.Tables("QuizQuestions").Rows.Count - 1
Dim lcHTML = New LiteralControl
lcHTML.Text = "<b>
" _
& Items.Tables("QuizQuestions").Rows(I).Item("Questi onText") & "</b>
"
TestRptr.Controls.Add(lcHTML)
Dim MyDDL = New RadioButtonList
TempID = Items.Tables("QuizQuestions").Rows(I).Item("Sectio nQuestionID")
MyDDL.ID = "Q" & TempID
DBCommand = New OleDbDataAdapter _
("Select AnswerText " _
& "From QuestionAnswers Where SectionQuestionID = " _
& TempID, DBConn)
DBCommand.Fill(Items, TempID)
---->Problem 2:
'Data Container does not recognize the above query and gives "not part of
QuizQuestions (first query on page) table" error when try to retrieve
AnswerText
'Loads Answers
For J = 0 To Items.Tables(TempID).Rows.Count - 1
Dim MyItem = New ListItem
MyItem.Text = Items.Tables(TempID).Rows(J).Item("AnswerText")
MyDDL.Items.Add(MyItem)
Next
TestRptr.Controls.Add(MyDDL)
Dim lcHTML2 = New LiteralControl
lcHTML2.Text = "
"
TestRptr.Controls.Add(lcHTML2)
Next
' Populates the repeater control with the Items DataSet
'Dim objPds As New PagedDataSource
objPds.DataSource = Items.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 1
objPds.CurrentPageIndex = CurrentPage
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of " +
objPds.PageCount.ToString()
' Disable Prev or Next buttons if necessary
PrevBtn.Enabled = Not objPds.IsFirstPage
NextBtn.Enabled = Not objPds.IsLastPage
TestRptr.DataSource = objPds
TestRptr.DataBind()
End Sub
Finally: The above code runs, the lblCurrenPage and Prev and Next buttons
appear as they should but do not move to next record(page). Also as mentioned
above only the QuestionText appears not the AnswerText. Help --- please!!!!!
--
Gracias in Advance!