473,387 Members | 1,673 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.

paging and sorting

Sir,

The default paging of datagrid is somehow use too much resource, so I am
using Stored procedure for the paging. You can find my Stored procedure at
the end of this message.

It works fine to do paging like this, however, I have found it difficult to
do paging and sorting at the same time.

For example, in my case, my boss asked me to do sorting on EmailAddress,
ZipCode, ActivityName and Coupon.

Any recommendation how should I achieve this?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com
<Paging Stored Procedure>

-- get activity subscribers per pages.
CREATE PROCEDURE Proc_PerPageActivity
@PageNr int,
@PageSize int
AS
-- create a temporary table with the columns we are interested in
CREATE TABLE #TempTable
(
TempId int IDENTITY PRIMARY KEY,
AutoId Int,
EmailAddress varchar(100),
ZipCode char(10),
ActivityName varchar(100),
Coupon varchar(50),
DateSend datetime

)
-- fill the temp table with all the topics for the
-- specified forum retrieved from the v_Forums_Topics view
INSERT INTO #TempTable
(
AutoId,
EmailAddress,
ZipCode,
ActivityName,
Coupon,
DateSend
)
SELECT
AutoId,
EmailAddress,
ZipCode,
ActivityName,
Coupon,
DateSend
FROM
vw_ActivitySubscribers Order By AutoId DESC
-- declare two variables to calculate the range of records to extract for
the specified page
DECLARE @StartId int
DECLARE @ToId int
-- calculate the first and last ID of the range of topics we need
SET @StartId = ((@PageNr - 1) * @PageSize) + 1
SET @ToID = @PageNr * @PageSize
-- select the page of records
SELECT AutoId, EmailAddress, ZipCode, ActivityName, Coupon,
dbo.DayOnly(DateSend) as DateEnter
FROM #TempTable WHERE TempId >= @StartId AND TempId <= @ToId
Order By AutoId DESC

GO

</Paging Stored Procedure>
Nov 18 '05 #1
1 1618
OK, I answer it myself.

The solution I have now is using Dynamic Sql, I can put sorting variable
after Order By

This sounds to be an Ok solution.

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

"Guoqi Zheng" <no@sorry.nl> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Sir,

The default paging of datagrid is somehow use too much resource, so I am
using Stored procedure for the paging. You can find my Stored procedure at the end of this message.

It works fine to do paging like this, however, I have found it difficult to do paging and sorting at the same time.

For example, in my case, my boss asked me to do sorting on EmailAddress,
ZipCode, ActivityName and Coupon.

Any recommendation how should I achieve this?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com
<Paging Stored Procedure>

-- get activity subscribers per pages.
CREATE PROCEDURE Proc_PerPageActivity
@PageNr int,
@PageSize int
AS
-- create a temporary table with the columns we are interested in
CREATE TABLE #TempTable
(
TempId int IDENTITY PRIMARY KEY,
AutoId Int,
EmailAddress varchar(100),
ZipCode char(10),
ActivityName varchar(100),
Coupon varchar(50),
DateSend datetime

)
-- fill the temp table with all the topics for the
-- specified forum retrieved from the v_Forums_Topics view
INSERT INTO #TempTable
(
AutoId,
EmailAddress,
ZipCode,
ActivityName,
Coupon,
DateSend
)
SELECT
AutoId,
EmailAddress,
ZipCode,
ActivityName,
Coupon,
DateSend
FROM
vw_ActivitySubscribers Order By AutoId DESC
-- declare two variables to calculate the range of records to extract for
the specified page
DECLARE @StartId int
DECLARE @ToId int
-- calculate the first and last ID of the range of topics we need
SET @StartId = ((@PageNr - 1) * @PageSize) + 1
SET @ToID = @PageNr * @PageSize
-- select the page of records
SELECT AutoId, EmailAddress, ZipCode, ActivityName, Coupon,
dbo.DayOnly(DateSend) as DateEnter
FROM #TempTable WHERE TempId >= @StartId AND TempId <= @ToId
Order By AutoId DESC

GO

</Paging Stored Procedure>

Nov 18 '05 #2

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

Similar topics

1
by: Dave S | last post by:
Hi, I'm using a datagrid to display contents of a dataset and I've set the datagrid to allow paging and sorting. Rather than re-retrieve from the DB, I store the original dataset in a Session...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: Hajime Kusakabe | last post by:
Hi. I have created a datagrid (datagrid1) without any columns on a aspx page. Then aspx.vb adds columns from a database. It is somthing like this .... ================================== Dim...
2
by: saleek | last post by:
Hi, I am trying to figure out why my datagrid has stopped firing the page and sort commands. Scenario: I originally had template columns in my datagrid and had set up custom bi-directional...
5
by: LDD | last post by:
Hi Folks I'm trying to determine a way to handle paging, filtering and sorting in a datagrid. If I choose to filter and sort, I'd like to return a subset. If that resultset has more records...
2
by: Kuldeep | last post by:
Hi All, I have been trying to find some algorithms for datagrid sorting and paging. Please help Regards Kuldeep
0
by: Roy | last post by:
Hey all, I must be losing my touch. I have made many pages in the 1.1 framework that utilize custom bidirectional paging in datagrids. We've converted over to 2.0 and I've been trying to use the...
0
by: anonieko | last post by:
This approach I found very efficient and FAST when compared to the rowcount, or Subquery Approaches. This is before the advent of a ranking function from DB such as ROW_NUMBER() in SQL Server...
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.