page=" + Convert.ToString(currentpage + 1); } else { hlnextpage.Enabled = false; } //转到首页 if (pds.CurrentPageIndex 要 (fldName + 0) AS fldName 这样处理;输入参数:@tblName: 表名 @strGetFields: 需要返回的列 '*':返回所以列信息@PageSize: 页尺寸@PageIndex: 页码@doCount: 返回记录总数 如果非要加入的话 在@strGetFields中不要加入此字段信息 则禁用下一页超链接 if ( page=" + Convert.ToString(1); } else { hlfirstpage.Enabled = false; } //转到末页 if (pds.CurrentPageIndex pds.IsLastPage) { //下一页 hlnextpage.NavigateUrl = Request.CurrentExecutionFilePath + " page=" + Convert.ToString(pages); } else { hllastpage.Enabled = false; } GridView1.DataSource = pds; GridView1.DataBind(); } ||| 存储过程:set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo/*功能描述: 通用分页显示查询如果有自增标识字段 如果当前页为最后一页 则禁用上一页超链接按钮 if ( = 0) { hlfirstpage.NavigateUrl = Request.CurrentExecutionFilePath + " page=" + Convert.ToString(currentpage - 1); } else { hlfrontpage.Enabled = false; } //下一页 如果当前为第一页 就执行总数统计IF (@doCount = pages - 1) { hllastpage.NavigateUrl = Request.CurrentExecutionFilePath + " = '')SET @strOrder = ' ORDER BY ' + @strOrderBy--如果是第一页就执行以上代码 = '')SET @strSQL = @strSQL + ' WHERE ' + @strWhere + @strOrderELSESET @strSQL = @strSQL + @strOrder--以下代码赋予了@strSQL以真正执行的SQL代码SET @strSQL = @strSQL + ' SELECT * FROM #tmpTable WHERE IID > ' + str((@PageIndex-1)*@PageSize) + ' DROP TABLE #tmpTable'ENDPRINT @strSQL--执行分页查询EXEC (@strSQL) 1) AS IID 1 ''IsUserTable'') = 1) 'SET @strSQL = @strSQL + ' UPDATE dbo.tmpTable SET Total = (SELECT count(*) from (select '+@strGetFields+' FROM ' + @tblName + ' ' + @sWhere + ') a) 'SET @strSQL = @strSQL + ' ELSE select count(*) as Total INTO dbo.tmpTable from (SELECT '+@strGetFields+' FROM ' + @tblName + ' ' + @sWhere+') a'print @strsqlEXEC (@strSQL)SELECT @RecordCount=Total FROM dbo.tmpTable--删除总数统计临时表EXEC ('DROP TABLE dbo.tmpTable')ENDPRINT @RecordCount--排序字段信息IF (@strOrderBy = '') SET @strSQL = 'SELECT TOP ' + str(@PageSize) + ' ' + @strGetFields + ' FROM ' + @tblName + ' WHERE ' + @strWhere + @strOrderELSESET @strSQL = 'SELECT TOP ' + str(@PageSize) + ' ' + @strGetFields + ' FROM '+ @tblName + ' '+ @strOrderENDELSEBEGIN--为搜索表建立自动编号 保存到临时表中SET @strSQL = 'SELECT TOP ' + str(@PageIndex*@PageSize) + ' IDENTITY(int @RecordCount int output)AS-- 主语句DECLARE @strSQL varchar(5000) SET @strSQL = ''-- 排序变量DECLARE @strOrder varchar(400) SET @strOrder = ''SET @RecordCount = 0--如果@doCount传递过来的不是0 ' + @strGetFields + ' INTO #tmpTable FROM ' + @tblName IF (@strWhere = null) { currentpage = Convert.ToInt32(Request.QueryString["page"].ToString()); } else { currentpage = 1; } TextBox1.Text = currentpage.ToString(); //设置当前页索引为显示页码-1 pds.CurrentPageIndex = currentpage - 1; //上一页 这样会加快执行速度IF (@PageIndex = 1)BEGINIF (@strWhere IsPostBack) { Business bs = new Business(); ddldepartment.DataSource = bs.ddlDepartment(); ddldepartment.DataTextField = "depname"; ddldepartment.DataValueField = "depname"; ddldepartment.DataBind(); ddleqkind.DataSource = bs.ddlEqkind(); ddleqkind.DataTextField = "eqkind"; ddleqkind.DataValueField = "eqkind"; ddleqkind.DataBind(); pds = new PagedDataSource(); dt = bs.EquipmentList(); pds.DataSource = dt.DefaultView; //允许分页 pds.AllowPaging = true; //数据源中的项数 int eqnumber = pds.DataSourceCount; lbnum.Text = eqnumber.ToString(); //每页的项数 pds.PageSize = 5; //总页数 int pages = pds.PageCount; lbpage.Text = pages.ToString(); //当前页的索引 int currentpage; if (Request.QueryString["page"] = '')SET @sWhere = ' WHERE ' + @strWhereSET @strSQL = 'if exists (select * from dbo.sysobjects where id = object_id(''dbo.tmpTable'') and OBJECTPROPERTY(id @strWhere varchar(1500) = '' @strOrderBy varchar(500) = '' @doCount bit = 0 @PageIndex int = 1 @PageSize int = 10 @strGetFields varchar(1000) = '*' (注意: 不要加 WHERE)输出参数: @RecordCount: 记录总数作 者: ningfeiyang创建时间: 2005-01-21更改纪录:*/ALTER PROCEDURE [dbo].[CommonPager](@tblName varchar(1000) Field2 ASC@strWhere: 查询条件 (注意: 不要加 ORDER BY)格式: Field1 DESC 非 0 值则返回@strOrderBy: 排序字段信息 分页类:if ( = 0)BEGINDECLARE @sWhere varchar(2000)SET @sWhere = ''IF (@strWhere pds.IsFirstPage) { //上一页 //Request.CurrentExecutionFilePath为当前请求的虚拟路径 hlfrontpage.NavigateUrl = Request.CurrentExecutionFilePath + "