473,770 Members | 5,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datalist pagination - How?

I am using a datalist on an ASP.NET 2.0 website. Any idea (or code
examples) how I can use pagination on a datalist?

Thanks!
Aug 1 '06 #1
4 2960
You can consider getting just one page of the data from the database with
sql parameters TOP and START AT.

Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"VB Programmer" <do**********@s omewhere.comwro te in message
news:ei******** *****@TK2MSFTNG P03.phx.gbl...
>I am using a datalist on an ASP.NET 2.0 website. Any idea (or code
examples) how I can use pagination on a datalist?

Thanks!

Aug 2 '06 #2
Here is an example:
1) A stored procedure that gets page of records from products table in
Northwind database
--------------------------------------------------------------------------------------
ALTER PROC usp_GetProducts Page
(
@pgNdx int,
@pgSize int,
@catId int = NULL
)
AS
-- create a temporary table with the columns we are interested in
CREATE TABLE #ProductsPage
(
RecordID int IDENTITY PRIMARY KEY,
ProductID int,
ProductName nvarchar(40),
UnitPrice money,
UnitsInStock smallint,
CategoryName nvarchar(15),
CompanyName nvarchar(40),
QuantityPerUnit nvarchar(20),
UnitsOnOrder smallint,
ReorderLevel smallint,
Discontinued bit,
CategoryId int,
SupplierId int
)
-- fill the temp table with all the employees
INSERT INTO #ProductsPage
(
ProductID,
ProductName,
UnitPrice,
UnitsInStock,
CategoryName,
CompanyName,
QuantityPerUnit ,
UnitsOnOrder,
ReorderLevel,
Discontinued,
CategoryID,
SupplierID
)
SELECT ProductID,Produ ctName,UnitPric e,UnitsInStock, CategoryName,
CompanyName,Qua ntityPerUnit,Un itsOnOrder,Reor derLevel,Discon tinued,
CategoryID,Supp lierID
FROM vw_ProductsList
WHERE CategoryID = @catId OR @catId IS NULL OR @catId=-1
ORDER BY ProductID

-- declare two variables to calculate the range of records
-- to extract for the specified page

DECLARE @fromId int
DECLARE @toId int
SET @fromId= (@pgNdx * @pgSize)
SET @toId= @fromId + @pgSize -1

-- select the page of records
SELECT * FROM #ProductsPage
WHERE (RecordID BETWEEN @fromId AND @toId)AND
(CategoryID = @catId OR @catId IS NULL OR @catId=-1)
GO
-- usp_GetProducts Page 0,10
---------------------------------------------------------------------------------
You will also need another procedures that returns total number of records
in your products table.

2)then I suggest for simplisity, to add a dropdownlist to your DataList
header or any where in the page, fill this dropdownlist with numbers from 1
to total number of pages which should be
pages = totalNumOfRecor ds / pageRecordsCoun t
increase the pages by 1 if the totalNumOfRecor ds Mod pageRecordsCoun t is
greater that 0

3)Now when the user change the page from the dropdownlist, you need to
submit the page number along with the page size to the above stored procedure.

I wish I could make clearer.. Please contact me by your e-mail and I'll
submit a full example to you if you wish.

Reagrds
Aug 2 '06 #3
Thanks. I'll look this over!

"Muhammad Mosa" <Muhammad Mo**@discussion s.microsoft.comwrote in message
news:2D******** *************** ***********@mic rosoft.com...
Here is an example:
1) A stored procedure that gets page of records from products table in
Northwind database
--------------------------------------------------------------------------------------
ALTER PROC usp_GetProducts Page
(
@pgNdx int,
@pgSize int,
@catId int = NULL
)
AS
-- create a temporary table with the columns we are interested in
CREATE TABLE #ProductsPage
(
RecordID int IDENTITY PRIMARY KEY,
ProductID int,
ProductName nvarchar(40),
UnitPrice money,
UnitsInStock smallint,
CategoryName nvarchar(15),
CompanyName nvarchar(40),
QuantityPerUnit nvarchar(20),
UnitsOnOrder smallint,
ReorderLevel smallint,
Discontinued bit,
CategoryId int,
SupplierId int
)
-- fill the temp table with all the employees
INSERT INTO #ProductsPage
(
ProductID,
ProductName,
UnitPrice,
UnitsInStock,
CategoryName,
CompanyName,
QuantityPerUnit ,
UnitsOnOrder,
ReorderLevel,
Discontinued,
CategoryID,
SupplierID
)
SELECT ProductID,Produ ctName,UnitPric e,UnitsInStock, CategoryName,
CompanyName,Qua ntityPerUnit,Un itsOnOrder,Reor derLevel,Discon tinued,
CategoryID,Supp lierID
FROM vw_ProductsList
WHERE CategoryID = @catId OR @catId IS NULL OR @catId=-1
ORDER BY ProductID

-- declare two variables to calculate the range of records
-- to extract for the specified page

DECLARE @fromId int
DECLARE @toId int
SET @fromId= (@pgNdx * @pgSize)
SET @toId= @fromId + @pgSize -1

-- select the page of records
SELECT * FROM #ProductsPage
WHERE (RecordID BETWEEN @fromId AND @toId)AND
(CategoryID = @catId OR @catId IS NULL OR @catId=-1)
GO
-- usp_GetProducts Page 0,10
---------------------------------------------------------------------------------
You will also need another procedures that returns total number of records
in your products table.

2)then I suggest for simplisity, to add a dropdownlist to your DataList
header or any where in the page, fill this dropdownlist with numbers from
1
to total number of pages which should be
pages = totalNumOfRecor ds / pageRecordsCoun t
increase the pages by 1 if the totalNumOfRecor ds Mod pageRecordsCoun t is
greater that 0

3)Now when the user change the page from the dropdownlist, you need to
submit the page number along with the page size to the above stored
procedure.

I wish I could make clearer.. Please contact me by your e-mail and I'll
submit a full example to you if you wish.

Reagrds

Aug 3 '06 #4
VB P
See a sample here at:-
http://www.dotnetjohn.com/articles.aspx?articleid=48
PAtrick

"VB Programmer" <do**********@s omewhere.comwro te in message
news:ue******** ******@TK2MSFTN GP02.phx.gbl...
Thanks. I'll look this over!

"Muhammad Mosa" <Muhammad Mo**@discussion s.microsoft.comwrote in message
news:2D******** *************** ***********@mic rosoft.com...
>Here is an example:
1) A stored procedure that gets page of records from products table in
Northwind database
--------------------------------------------------------------------------------------
ALTER PROC usp_GetProducts Page
(
@pgNdx int,
@pgSize int,
@catId int = NULL
)
AS
-- create a temporary table with the columns we are interested in
CREATE TABLE #ProductsPage
(
RecordID int IDENTITY PRIMARY KEY,
ProductID int,
ProductName nvarchar(40),
UnitPrice money,
UnitsInStock smallint,
CategoryName nvarchar(15),
CompanyName nvarchar(40),
QuantityPerUni t nvarchar(20),
UnitsOnOrder smallint,
ReorderLevel smallint,
Discontinued bit,
CategoryId int,
SupplierId int
)
-- fill the temp table with all the employees
INSERT INTO #ProductsPage
(
ProductID,
ProductName,
UnitPrice,
UnitsInStock ,
CategoryName ,
CompanyName,
QuantityPerUni t,
UnitsOnOrder ,
ReorderLevel ,
Discontinued ,
CategoryID,
SupplierID
)
SELECT ProductID,Produ ctName,UnitPric e,UnitsInStock, CategoryName,
CompanyName,Qu antityPerUnit,U nitsOnOrder,Reo rderLevel,Disco ntinued,
CategoryID,Sup plierID
FROM vw_ProductsList
WHERE CategoryID = @catId OR @catId IS NULL OR @catId=-1
ORDER BY ProductID

-- declare two variables to calculate the range of records
-- to extract for the specified page

DECLARE @fromId int
DECLARE @toId int
SET @fromId= (@pgNdx * @pgSize)
SET @toId= @fromId + @pgSize -1

-- select the page of records
SELECT * FROM #ProductsPage
WHERE (RecordID BETWEEN @fromId AND @toId)AND
(CategoryID = @catId OR @catId IS NULL OR @catId=-1)
GO
-- usp_GetProducts Page 0,10
---------------------------------------------------------------------------------
You will also need another procedures that returns total number of
records
in your products table.

2)then I suggest for simplisity, to add a dropdownlist to your DataList
header or any where in the page, fill this dropdownlist with numbers from
1
to total number of pages which should be
pages = totalNumOfRecor ds / pageRecordsCoun t
increase the pages by 1 if the totalNumOfRecor ds Mod pageRecordsCoun t is
greater that 0

3)Now when the user change the page from the dropdownlist, you need to
submit the page number along with the page size to the above stored
procedure.

I wish I could make clearer.. Please contact me by your e-mail and I'll
submit a full example to you if you wish.

Reagrds


Aug 3 '06 #5

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

Similar topics

9
3407
by: Sharif T. Karim | last post by:
Anyone know of a up-to-date tutorial for pagination where I can have it like: Prev 1 2 3 4 Next Thanks. -- Sharif T. Karim ....you don't know wrath yet...
1
5817
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
0
1125
by: Kruq | last post by:
Is it possible to pagine DataList? regards Kruq
2
2329
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't functioning or the $page variable isnt working in that part of the code... Below is the link to the working but broken page.. as well as the main part of my code... Hopefully someone can explain why the operators arent working or maybe see what i...
11
2782
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by going to url's like mywebsite/gallery.php?category=landscape Although the above worked perfectly...
1
6851
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that i have written for pagination but it displays the link of all the pages at one go i.e. if i have 8 pages showing 10 results per page than it shows links for all 8 pages. Previous 1-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 Next i want to...
16
2781
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between...
4
3575
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the page is blank. I have seen people mention this problem, and they have been told that a variable is...
2
2594
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters kindly help <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title>
0
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.