Datalist Question

G

Guest

I'm trying to page a Datalist below using VS.NET
But i get the error:-
System.NullReferenceException: Object reference not set to an instance of an
object.

At line:- btnPrev.Visible = (Not pagedData.IsFirstPage)

When i try the code using ASP.NET WebMatrix it works?
What am i doing wrog?
Thx
----------------------------------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.DataView
Imports System.Data.DataTable


Public Class paging_datalist2aspx
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Protected WithEvents theDataList As DataList

Dim pagedData As New PagedDataSource
Dim pageNumber As Label
Dim btnPrev, btnNext As Button

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
doPaging()
End If

End Sub

Function getTheData() As DataTable
Dim DS As New DataSet
Dim strConnect As New
SqlConnection(ConfigurationSettings.AppSettings("northwind"))
Dim objSQLAdapter As New SqlDataAdapter("SELECT companyName,
contactName, contactTitle FROM customers", strConnect)
objSQLAdapter.Fill(DS, "customers")

Return DS.Tables("customers").Copy
End Function

Sub doPaging()
pagedData.DataSource = getTheData().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
 
G

Guest

I guess i knew what i was doing wrong..:)
But when i click on the link to page to the next page after the first 5 it
doesn't go to
the next page..
Guess 'm tired..
But am i doing wrong!
 

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

Top