473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Datalist Question

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("n orthwind"))
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

Nov 18 '05 #1
1 1257
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!

"Patrick.O.Ige" wrote:
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("n orthwind"))
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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob Manger | last post by:
Hi All, This may be a stupid question, and may not be the correct solution for my problem, but here goes. I want to include a datalist within a datalist, in order to effectively group items...
0
by: ani | last post by:
I have few questions regarding datalist control. 1) How do I retrieve the values that are present in the datalist control. My aspx page actually reloads to itself, and the datalist control has...
1
by: Glenn Owens | last post by:
Here's the scenario: I have a DataList populated from a datatable sitting inside a fieldset. Each element (row) in the Datalist has the following child controls: asp:checkbox, asp:image,...
4
by: tshad | last post by:
I have a DataList that I have set up to allow editing. The edit button does go to the subroutine defined by OnEditCommand. The problem is that it doesn't change the fields to editing fields. The...
0
by: Patrick Olurotimi Ige | last post by:
I have a Datalist and i want CheckBoxes in it. The Datalist is popluated from the Database. I want to be able to select the checkboxes with the populated Datalist and insert to table. But i want...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
1
by: Craig | last post by:
This is killing me, I've been trying to figure this out for 2 days. When I click on the linkbutton, it executes the GetData(int) method to set the DataSource. The FAILURE is when it tries to...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
3
by: rn5a | last post by:
I want to change the background color of a row in a DataList when the mouse is moved over a row. This is how I tried but it doesn't change the background color of a row in the DataList when the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.