自定义分页..我想显示数据库(sql server 2008)中的前10条记录到网格视图 [英] custom paging.. i want to show first 10 record from database(sql server 2008) into grid view

查看:171
本文介绍了自定义分页..我想显示数据库(sql server 2008)中的前10条记录到网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想使用存储过程从数据库中显示前10条记录,并希望在网格视图中并单击第一个索引时显示编号(例如1234 ... n)
想要显示记录1-10并单击2nd 11-20

Hello i want to display first 10 records from the database using Store procedure and want to show numbering(like 1234...n) in a grid view and on the click of first index
want to show record 1-10 and on the click of 2nd 11-20

推荐答案

朋友,


U可以为网格视图设置分页属性,

并将分页大小设置为10.
Hi Friend,


U can set paging property for grid view,

and set paging size is 10 .


select * from
(
select row_number over(partition by id,name order by id,name) as index_no,--this will assign row no 1,2,3,...
id,name
from tbl 
) as a
where index_no>@StartIndex --pass here from-to record-no range.
      and index_no<@EndIndex



传递参数``@StartIndex''&单击按钮时的"@EndIndex"范围.例如. 1-10、11-20,...
祝您编码愉快!
:)



pass parameters ''@StartIndex'' & ''@EndIndex'' range while clicking button. eg. 1-10, 11-20,...
Happy Coding!
:)


CREATE PROCEDURE [dbo].[asp_Pagingtest]
( @index as int     =1  )

Begin

--something
--something

--something

 Declare @StartIndex as int=((@index-1)*10)+1
Declare @EndIndex as Int=@index*10


With CTE_Count as
(Select EmpId,ROW_NUMBER() OVER (ORDER BY  S.LastName) AS RowNumber
 from table_temp )
Select * from table_temp where EmpId in (select EmpId from CTE_COunt where rownumber between @StartIndex  and @EndIndex)

END



这里@Index默认为pageno,我们必须显示第一页. EmpId是我要在其中提取记录的表的主键



Here @Index is the pageno by default, we have to dispaly first page. EmpId is the primary key for the table where i am going to pull records


这篇关于自定义分页..我想显示数据库(sql server 2008)中的前10条记录到网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆