473,387 Members | 1,899 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,387 software developers and data experts.

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 2947
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**********@somewhere.comwrote in message
news:ei*************@TK2MSFTNGP03.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_GetProductsPage
(
@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,ProductName,UnitPrice,UnitsInStock,Categ oryName,
CompanyName,QuantityPerUnit,UnitsOnOrder,ReorderLe vel,Discontinued,
CategoryID,SupplierID
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_GetProductsPage 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 = totalNumOfRecords / pageRecordsCount
increase the pages by 1 if the totalNumOfRecords Mod pageRecordsCount 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**@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
Here is an example:
1) A stored procedure that gets page of records from products table in
Northwind database
--------------------------------------------------------------------------------------
ALTER PROC usp_GetProductsPage
(
@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,ProductName,UnitPrice,UnitsInStock,Categ oryName,
CompanyName,QuantityPerUnit,UnitsOnOrder,ReorderLe vel,Discontinued,
CategoryID,SupplierID
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_GetProductsPage 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 = totalNumOfRecords / pageRecordsCount
increase the pages by 1 if the totalNumOfRecords Mod pageRecordsCount 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**********@somewhere.comwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
Thanks. I'll look this over!

"Muhammad Mosa" <Muhammad Mo**@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
>Here is an example:
1) A stored procedure that gets page of records from products table in
Northwind database
--------------------------------------------------------------------------------------
ALTER PROC usp_GetProductsPage
(
@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,ProductName,UnitPrice,UnitsInStock,Categ oryName,
CompanyName,QuantityPerUnit,UnitsOnOrder,ReorderL evel,Discontinued,
CategoryID,SupplierID
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_GetProductsPage 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 = totalNumOfRecords / pageRecordsCount
increase the pages by 1 if the totalNumOfRecords Mod pageRecordsCount 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
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
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
0
by: Kruq | last post by:
Is it possible to pagine DataList? regards Kruq
2
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...
11
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. ...
1
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...
16
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) ...
4
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,...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.