Click here to Skip to main content
15,888,079 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello!

I`m making website, and now I`m building board using GridView.

it needed custom paging and some rows must be placed on the top of the list(every page)

I`m building my girdview using this sites

Custom Paging with GridView

someone helped me, and I completed the make stored procedure below, bur sorting is not working

if BoardNotice value is Y, that rows must be placed on the top of the list and N value rows

placed below... like this

BoardTitle UserName BoardNotice

test john Y
test2 tom Y
test3 joe N
test4 zoey N
test5 carter N
test6 tony N

Please, fix my code or some advice to me.. thanks

What I have tried:

ALTER PROCEDURE [dbo].[TestCustomPaging]
@BoardID int --FK(PK in tb_BoardMaster, I have 3 Boards)
, @PageIndex int
, @PageSize int
, @RecordCount int output
AS
BEGIN
SET NOCOUNT ON;

;with cte as (
SELECT
ROW_NUMBER() OVER (ORDER BY I.BoardItemID desc) AS indexNO
, I.BoardItemID -- PK
, I.BoardTitle
, I.UserName
, I.BoardRegDate
, I.BoardHit
, I.BoardNotice -- To verify notice or not(default value is N(not notice))
, (SELECT COUNT(FileID) FROM tb_AttachedFiles A WHERE A.BoardItemID = I.BoardItemID) AS FileCount
FROM tb_BoardItem I
WHERE BoardID = @BoardID
)
SELECT * FROM cte
WHERE
indexNO BETWEEN (@PageIndex -1) * @PageSize +1 AND (((@PageIndex -1) * @PageSize +1) + @PageSize) -1

END
Posted
Updated 17-Aug-16 0:25am

1 solution

Hi again Rydenchoi

try adding this:
SQL
ORDER BY I.BoardNotice DESC
after
SQL
SELECT * FROM cte
WHERE
indexNO BETWEEN (@PageIndex -1) * @PageSize +1 AND (((@PageIndex -1) * @PageSize +1) + @PageSize) -1
 
Share this answer
 
v2
Comments
RydenChoi 18-Aug-16 0:58am    
Hi njammy, thanks your comment. I already tried like that,but the result is quite different what I want. I want to show "BoardNotice = Y" values rows place on the top of list, but that code, if page 1 has 1 item(BoardNotice = Y) it placed on the top of the list, but other pages item(BoardNotice=Y) never showed on the list. Which means, items only showed the top of list in their page,
njammy 18-Aug-16 4:15am    
That does not make sense sorry, the example I tried works. Check your SQL.
RydenChoi 19-Aug-16 4:58am    
Oh It`s alright, I finally fixed my code and now it works well,
Thanks for your comment!! :)
njammy 19-Aug-16 5:16am    
If you fixed it please upload your fixed code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900