第一 存储过程
存储过程1:从数据库取得要查询记录的总条数
CREATE procedure P_PageSP
@Lower varchar(4), --要查询的下限
@Upper varchar(4), --要查询的上限
@TableName varchar(100), --查询的表名
@OrderBy varchar(200), --排序条件
@FilterStr varchar(1000), --过滤条件
@Sql varchar(2000) --查询语句
AS
declare @Str varchar(2000)
set @Str ='
declare @indextable table(id int identity(1,1),nid int);
insert into @indextable(nid) select [ID] from (' + @Sql + ' ' + @FilterStr + ') as a ' + @OrderBy + ' ;
' + @Sql + ' inner join @indextable t on t.nid='+ @TableName +'.ID
where t.id > ' + @Lower + ' and t.id <= ' + @Upper + ' '
exec(@Str)
GO
@Lower varchar(4), --要查询的下限
@Upper varchar(4), --要查询的上限
@TableName varchar(100), --查询的表名
@OrderBy varchar(200), --排序条件
@FilterStr varchar(1000), --过滤条件
@Sql varchar(2000) --查询语句
AS
declare @Str varchar(2000)
set @Str ='
declare @indextable table(id int identity(1,1),nid int);
insert into @indextable(nid) select [ID] from (' + @Sql + ' ' + @FilterStr + ') as a ' + @OrderBy + ' ;
' + @Sql + ' inner join @indextable t on t.nid='+ @TableName +'.ID
where t.id > ' + @Lower + ' and t.id <= ' + @Upper + ' '
exec(@Str)
GO
第二 自定义按钮控件
aspx代码
第三 应用
把自定义控件拖到用于分页的GridView页面上,属性栏设置GridView的各个属性(都有详细的属性说明)。页面CS代码需要绑定GridView的地方调用自定义控件的BindGridView()方法绑定数据(如果是查询页面调用方法之前应先设置控件的FilterStr属性)。