473,402 Members | 2,046 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,402 software developers and data experts.

DataList Paging

Hello.

How can I enable and manage paging capability on DataList control like
DataGrid?

Thank you.
Nov 19 '05 #1
2 5366
Hello,

The trick when using a DataList to page data is to think about where
the paging occurs. Since the DataList does not support paging but
does support being bound to a DataSet. If it were simple the story
would end here. Unfortunately a DataSet does not support paging
either. So what you need to do is make your DataSet a single page of
data! This way you only retrieve the data you need for a single page.

See http://www.dotnetjunkies.com/Tutoria...179-4563-B053-
2742516BF05B.dcik
How can I enable and manage paging capability on DataList control like
DataGrid? Thank you.

Nov 19 '05 #2
There is class named PagedDataSource that can be used to build custom paging
for the datalist and/or repeater.
Here is some sample code that shows how to use it:

================================================== =======================
'declare some variables at the top of the page:

Protected pagedData As New PagedDataSource
Private mPageNo As Integer = 1

' add lblPages to your form where you want the page numbers to appear.
================================================== =======================

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
If Request.QueryString("PageNo") Is Nothing Then
GetData()
doPaging()
Else
doPaging()
End If
End If

End Sub

================================================== =======================

Sub GetData()
'get collection or dataset for the page here
End Sub

================================================== =======================
Sub doPaging()

'use QueryString values for mPageNo
If Not Request.QueryString("PageNo") Is Nothing Then
mPageNo = CInt(Request.QueryString("PageNo"))
End If

'set the pagedData Properties
pagedData.CurrentPageIndex = mPageNo - 1
pagedData.DataSource = myCollection 'or Dataset
pagedData.AllowPaging = True
pagedData.PageSize = 5

'draw the page numbers as hyperlinks
lblPages.Text = DrawPaging(mPageNo, pagedData.PageCount)

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

================================================== =======================
Public Function DrawPaging(ByVal pageNumber As Integer, ByVal pageCount
As Integer) As String

Dim sb As New StringBuilder
Dim x, y, z, pageEnd, pageStart As Integer

If pageCount > 1 Then

'handle 10 at a time
'get the start and end
If pageNumber Mod 10 = 0 Then '10, 20, 30 appear with old set
pageStart = pageNumber - 9
Else
y = pageNumber.ToString.Length

If y = 1 Then '1 - 9
pageStart = 1
Else
z = CInt(Left(pageNumber.ToString, y - 1))
pageStart = (z * 10) + 1
End If
End If

If pageStart + 9 > pageCount Then
pageEnd = pageCount
Else
pageEnd = pageStart + 9
End If

'draw the Previous 10 if not in the first 10
If pageStart > 10 Then
sb.Append("<a href=")
sb.Append(DrawLink(pageStart - 1))
sb.Append(">Previous 10</a>&nbsp;&nbsp;&nbsp;&nbsp;")
End If

'draw the previous button if not at the first item on the first page
If pageNumber <> 1 Then
sb.Append("<a href=")
sb.Append(DrawLink(pageNumber - 1))
sb.Append("><</a>&nbsp;&nbsp;")
Else
sb.Append("&nbsp;&nbsp;")
End If

'draw the page numbers (current page is not a hyperlink it is in
bold in square brackets)
For x = pageStart To pageEnd
If x = pageNumber Then
sb.Append("<strong>[")
sb.Append(x)
sb.Append("]</strong>&nbsp;&nbsp;")
Else
sb.Append("<a href=")
sb.Append(DrawLink(x))
sb.Append(">")
sb.Append(x)
sb.Append("</a>&nbsp;&nbsp;")
End If
Next

'draw the next button if not at the last page
If pageNumber < pageCount Then
sb.Append("<a href=")
sb.Append(DrawLink(pageNumber + 1))
sb.Append(">></a>")
Else
sb.Append("&nbsp;&nbsp;")
End If

'draw the Next 10 if number range not more than total page count
If pageEnd < pageCount Then
sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;<a href=")
sb.Append(DrawLink(pageEnd + 1))
sb.Append(">Next 10</a>")
End If

sb.Append("<small><br>Total Page Count: ")
sb.Append(pageCount)
sb.Append("</small>")
sb.Append("</CENTER>")

Return sb.ToString
End If
End Function

================================================== =======================
Private Function DrawLink(ByVal pageNumber As Integer) As String
Return "?PageNo=" & pageNumber
End Function
================================================== =======================

--
Joe Fallon

"David" <da*********@hotmail.com> wrote in message
news:em**************@tk2msftngp13.phx.gbl...
Hello.

How can I enable and manage paging capability on DataList control like
DataGrid?

Thank you.

Nov 19 '05 #3

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

Similar topics

0
by: Andy | last post by:
Hello Guys: I am not sure if this is where the post belongs or not. I am using C# to write an ASP.Net page. I have an issue where I want to use a DataGrid, becasue of the Paging aspect, but...
3
by: Clint | last post by:
Hi, I am trying to implement the custom paging in the datalist in this format: << Prev 1,2,3,4,5 Next >>. Does anyone knows how to do this. Thanks in advance. Clint
3
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using...
5
by: Aahz | last post by:
Hello; I have an XML file with data which I show in DataList sucessfully, using DataSet Problem is that XML has about 30 records which is too much I need to show just first 10 ordered by date...
2
by: fa_2064 | last post by:
hi guys, how can i paging a datalist?is there a simple way or should be wrtite it's code manually???
0
by: needin4mation | last post by:
Hi, I have read many different datalist paging solutions, including using the ROW_NUMBER() with Sql Server 2005. I have googled various methods to use with lower versions of Sql Server. I...
4
by: 1333 | last post by:
Is it possible to have a Datalist with an Edit mode (<EditItemTemplate />) and custom paging? I can get <EditItemTemplate> mode and custom paging to work seperately but not together. I can delete...
0
by: | last post by:
I'm interested in paging a ASP.NET datalist. The ASP.NET datalist control does not natively support paging. I am binding an XmlDataSource (which is populated by entries in the filesystem) to the...
1
by: Aussie Rules | last post by:
Hi, Is it possible to have some sort of paging (prev/next page) feature with the data list. I have a datalist, that can display several hundred items, and I want to have say 20 to a page. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.