System.NullReferenceException: Object reference not set to an inst

G

Guest

Why if i try paging with PagedDataSource i get the error:-
System.NullReferenceException: Object reference not set to an instance of an
object.
THE ERROR LINE IS AT :-" btnPrev.Visible = (Not pagedData.IsFirstPage)"

My code below:-
Dim pagedData As New PagedDataSource

Dim pageNumber As Label
Dim btnPrev, btnNext As Button

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
SqlConnection("server=(local);database=Northwind;integrated security=true;")
Dim objSQLAdapter As New SqlDataAdapter("SELECT * from treetable",
strConnect)
objSQLAdapter.Fill(DS, "treetable")
Return DS.Tables("treetable").Copy


End Function

Sub doPaging()
pagedData.DataSource = getTheData().DefaultView
'pagedData.DataSource = DS.Tables(0).DefaultView
pagedData.AllowPaging = True
pagedData.PageSize = 5

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

theDataList.DataSource = pagedData
theDataList.DataBind()
End Sub

Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" &
(pagedData.CurrentPageIndex - 1))
End Sub

Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" &
(pagedData.CurrentPageIndex + 1))
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top