分页如何实现GridView的手动分页

gridview分页  时间:2021-02-11  阅读:()

如何实现GridView的手动分页

我们可以这样做。先要在Html界面中GridView中增加AllowPaging="True"接着做下面的

//在page_load事件中将GridView绑定数据库protected void Page_Load(object sender, EventArgs e)

{string sqlstr=select * from TABLE;sqlconnection conn=new sqlconnection("数据库连接字串") ;

DataSet mydataset = new DataSet() ;

SqlDataAdapter myds = new SqlDataAdapter() ;myds.SelectCommand = new SqlCommand(sqlstr, conn) ;myds.Fill (mydataset) ;this.GridView1.DataSource = mydataset;mydataset.Dispose() ;myds.Dispose() ;conn.Close() ;conn.Dispose() ;

GridView1.DataBind() ;

}

//GridView有一个PageIndexChanging事件protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

GridView1.PageIndex = e.NewPageIndex;

GridView1.DataBind() ;

}

这样就可以实现啦

要使用手动分页前提是GridView没有使用数据源控件(sqldatasource. . . . . )的时候。

请教GridView的手动分页如何实现谢谢!

请教GridView的手动分页(自定义分页)如何实现

比如已知有10000条数据我要GridView的分页功能来显示数据但是自动分页功能需要每次都取出全部的10000条数据这样效率不高

所以就要求只用设置GridView的分页数如1000页(每页10知)  当选择第n页时才从数据库中取出对应的数据请问怎样实现

谢谢!

ASP.NET结合存储过程写的通用搜索分页程序

存储过程改自bigeagle的论坛分页程序。请大家批判  select.aspx

-----------

<%@ Page Language="C#" %>

<%@ import Namespace="System.Data" %>

<%@ import Namespace="System.Data.SqlClient" %>

<script runat="server">protected void Page_Load(Object sender, EventArgs e)

{int intPageNo, intPageSize, intPageCount;intPageSize = 25;if (Request["CurrentPage"]==null)

{intPageNo = 1 ;

}else

{intPageNo = Int32.Parse(Request["CurrentPage"]) ;

}

SqlConnection mySqlConnection = new

SqlConnection("server=(local) ;Database=test;user id=sa;password=") ;SqlCommand mySqlCommand = new

SqlCommand("up_GetTopicList", mySqlConnection) ;mySqlCommand.CommandType = CommandType.StoredProcedure;SqlParameter workParm;

//搜索表字段 以", "号分隔workParm = mySqlCommand.Parameters.Add("@a_TableList",SqlDbType.VarChar, 200) ;mySqlCommand.Parameters["@a_TableList"] .Value =

"OFFERID, type,offertime";

//搜索表名workParm = mySqlCommand.Parameters.Add("@a_TableName",SqlDbType.VarChar, 30) ;mySqlCommand.Parameters["@a_TableName"] .Value = "offer";//搜索条件如"select * from aa where a=1 and b=2 and c=3"

则条件为"where a=1 and b=2 and c=3"workParm = mySqlCommand.Parameters.Add("@a_SelectWhere",SqlDbType.VarChar, 500) ;mySqlCommand.Parameters["@a_SelectWhere"] .Value = "wheretype=' idl' ";

//表主键字段名必须为INT类型workParm =mySqlCommand.Parameters.Add("@a_SelectOrderId", SqlDbType.VarChar, 50) ;mySqlCommand.Parameters["@a_SelectOrderId"] .Value ="offerid";

//排序可以使用多字段排序但主键字段必需在最前面workParm = mySqlCommand.Parameters.Add("@a_SelectOrder",SqlDbType.VarChar, 50) ;mySqlCommand.Parameters["@a_SelectOrder"] .Value = "orderby offerid desc";

//页号workParm = mySqlCommand.Parameters.Add("@a_intPageNo",SqlDbType. Int) ;mySqlCommand.Parameters["@a_intPageNo"] .Value= intPageNo;

//每页显示数workParm = mySqlCommand.Parameters.Add("@a_intPageSize",SqlDbType. Int) ;mySqlCommand.Parameters["@a_intPageSize"] .Value =intPageSize;

//总记录数(存储过程输出参数)workParm = mySqlCommand.Parameters.Add("@RecordCount",SqlDbType. Int) ;workParm.Direction =

ParameterDirection.Output;

//当前页记录数(存储过程返回值)workParm = mySqlCommand.Parameters.Add("RowCount",SqlDbType. Int) ;workParm.Direction = ParameterDirection.ReturnValue;mySqlConnection.Open() ;

Repeater.DataSource =mySqlCommand.ExecuteReader() ;

Repeater.DataBind() ;mySqlConnection.Close() ;

Int32 RecordCount =

(Int32)mySqlCommand.Parameters["@RecordCount"] .Value;Int32 RowCount =

(Int32)mySqlCommand.Parameters["RowCount"] .Value;

LabelRecord.Text = RecordCount.ToString() ;LabelRow.Text = intPageNo.ToString() ;intPageCount = RecordCount/intPageSize;if ( (RecordCount%intPageSize)>0)intPageCount += 1 ;

LabelPage.Text = intPageCount.ToString() ;if (intPageNo>1)

{

HLFistPage.NavigateUrl =

"select.aspx?CurrentPage=1";

HLPrevPage.NavigateUrl =

String.Concat("select.aspx?CurrentPage=", "", intPageNo-1) ;}else

{

HLFistPage.NavigateUrl = "";

HLPrevPage.NavigateUrl = "";

//HLFistPage.Enabled = false;

//HLPrevPage.Enabled = false;

}if (intPageNo<intPageCount)

{

HLNextPage.NavigateUrl =

String.Concat("select.aspx?CurrentPage=", "", intPageNo+1) ;

HLEndPage.NavigateUrl =

String.Concat("select.aspx?CurrentPage=", "", intPageCount) ;}else

{

HLNextPage.NavigateUrl = "";

HLEndPage.NavigateUrl = "";

//HLNextPage.Enabled=false;

//HLEndPage.Enabled=false;

}

}

</script>

<html>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><head>

<link href="/style.css" rel="stylesheet" />

<style type="text/css">

.high { font-family: "宋体"; font-size: 9pt; line-height: 140%}.mid { font-size: 9pt; line-height: 12pt}

. small { font-size: 9pt; line-height: normal}

.TP10_5 {font-size: 14px;line-height: 140%;

}

</style>

<style type="text/css">A:link {

COLOR: #cc6666

}

</style>

</head>

<body>

<form runat="server">

<span class="high"> 第<font color="#CC0000"><asp:Labelid="LabelRow" runat="server"/></font>页|共有<asp:Labelid="LabelPage" runat="server"/>页

| <asp:Label id="LabelRecord" runat="server"/>条信息|

<asp:HyperLink id="HLFistPage" Text="首页"runat="server"/>

| <asp:HyperLink id="HLPrevPage" Text="上一页"runat="server"/>

| <asp:HyperLink id="HLNextPage" Text="下一页"runat="server"/>

| <asp:HyperLink id="HLEndPage" Text="尾页"runat="server"/></span><br>

<asp:Repeater id=Repeater runat="server">

<HeaderTemplate>

<table width="583" border="0" cellspacing="0" cellpadding="0">

<tr>

<td bgcolor="#000000"><table width="100%" border="0"

cellpadding="4" cellspacing="1" class="TP10_5">

<tr bgcolor="#999999">

<td align="center"> <strong><font color="#FFFFFF">订单号</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">服务项目</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">预订日期</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">操作人员</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">分配状态</font></strong></td>

<td> <div align="center"></div></td>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr align="center" bgcolor="#FFFFFF" class="small"onMouseOver=' this. style.background="#CCCCCC"'onMouseOut=' this. style.background="#FFFFFF"' >

<td><%# DataBinder.Eval (Container.DataItem,

"offerid") %></td>

<td><%# DataBinder.Eval (Container.DataItem,

"type") %></td>

<td><%# DataBinder.Eval (Container.DataItem,

"offertime") %></td>

<td> </td>

<td> </td>

<td><ahref="javascript:void(window.open(' info.asp?id=<%#

DataBinder.Eval (Container.DataItem, "offerid") %>' , '订单分配

' , 'height=600,width=1000' ) )">订单详情</a></td>

</tr>

</ItemTemplate>

<FooterTemplate>

</table></td>

</tr>

</table>

</FooterTemplate>

</asp:Repeater>

</form>

</body>

</html>

---------------------------------------------------------------------

-----------up_GetTopicList. sql

---------------------------------------------------------------------

-----------

CREATE proc up_GetTopicList

@a_TableList Varchar(200) ,

@a_TableName Varchar(30) ,

@a_SelectWhere Varchar(500) ,

@a_SelectOrderId Varchar(20) ,

@a_SelectOrder Varchar(50) ,

@a_intPageNo int,

@a_intPageSize int,

@RecordCount int OUTPUTas

/*定义局部变量*/declare @intBeginID intdeclare @intEndID intdeclare @intRootRecordCount intdeclare @intRowCount intdeclare @TmpSelect NVarchar(600)

/*关闭计数*/set nocount on

/*求总共根贴数*/select @TmpSelect = ' set nocount on;select @SPintRootRecordCount =count(*) from '+@a_TableName+' '+@a_SelectWhereexecute sp_executesql

@TmpSelect,

N'@SPintRootRecordCount int OUTPUT' ,

@SPintRootRecordCount=@intRootRecordCount OUTPUTselect @RecordCount = @intRootRecordCount

if (@intRootRecordCount = 0) --如果没有贴子则返回零return 0

/*判断页数是否正确*/if (@a_intPageNo - 1) * @a_intPageSize > @intRootRecordCountreturn (-1)

/*求开始rootID*/set @intRowCount = (@a_intPageNo - 1) * @a_intPageSize + 1

/*限制条数*/select @TmpSelect = ' set nocount on;set rowcount

@SPintRowCount;select @SPintBeginID = '+@a_SelectOrderId+' from'+@a_TableName+' '+@a_SelectWhere+' '+@a_SelectOrder

execute sp_executesql

@TmpSelect,

N'@SPintRowCount int,@SPintBeginID int OUTPUT' ,

@SPintRowCount=@intRowCount,@SPintBeginID=@intBeginIDOUTPUT

/*结束rootID*/set @intRowCount = @a_intPageNo * @a_intPageSize

/*限制条数*/select @TmpSelect = ' set nocount on;set rowcount

@SPintRowCount;select @SPintEndID = '+@a_SelectOrderId+' from'+@a_TableName+' '+@a_SelectWhere+' '+@a_SelectOrder

execute sp_executesql

@TmpSelect,

N'@SPintRowCount int,@SPintEndID int OUTPUT' ,

@SPintRowCount=@intRowCount,@SPintEndID=@intEndID OUTPUTif @a_SelectWhere=' ' or @a_SelectWhere IS NULL

select @TmpSelect = ' set nocount off;set rowcount 0;select'+@a_TableList+' from '+@a_TableName+' where '+@a_SelectOrderId+'

between 'elseselect @TmpSelect = ' set nocount off;set rowcount 0;select'+@a_TableList+' from '+@a_TableName+' '+@a_SelectWhere+' and

'+@a_SelectOrderId+' between '

if @intEndID > @intBeginIDselect @TmpSelect = @TmpSelect+'@SPintBeginID and @SPintEndID'+'

'+@a_SelectOrder

elseselect @TmpSelect = @TmpSelect+'@SPintEndID and @SPintBeginID'+''+@a_SelectOrderexecute sp_executesql

@TmpSelect,

N'@SPintEndID int,@SPintBeginID int' ,

@SPintEndID=@intEndID,@SPintBeginID=@intBeginIDreturn(@@rowcount)

--select @@rowcount

GO

炭云188元/年,上海CN2 VPS/2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP

炭云怎么样?炭云(之前的碳云),国人商家,正规公司(哈尔滨桓林信息技术有限公司),主机之家测评介绍过多次。现在上海CN2共享IP的VPS有一款特价,上海cn2 vps,2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP/Hyper-v,188元/年,特别适合电信网络。有需要的可以关注一下。点击进入:炭云官方网站地址炭云vps套餐:套餐cpu内存硬盘流量/带宽ip价格购买上...

LOCVPS:VPS主机全场8折,德国/荷兰/美国KVM终身7折

LOCVPS发来了针对元旦新年的促销活动,除了全场VPS主机8折优惠外,针对德国/荷兰KVM #1/美国KVM#2 VPS提供终身7折优惠码(限量50名,先到先得)。LOCVPS是一家成立于2012年的国人VPS服务商,提供中国香港、韩国、美国、日本、新加坡、德国、荷兰、俄罗斯等地区VPS服务器,基于KVM或XEN架构(推荐优先选择KVM),均选择直连或者优化线路,国内延迟低,适合建站或远程办公使...

提速啦(900元/月),杭州BGP E5-2665/89*2 32核 48G 100G防御

提速啦的来历提速啦是 网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑提速啦的市场定位提速啦主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。提速啦的售后保证提速啦退款 通过于合作商的友好协商,云服务器提供3天内全额退款,超过3天不退款 物理机部分支持当天全额退款提速啦提现 充...

gridview分页为你推荐
刷网站权重刷出来的流量会提高网站的权重吗?在线代理网站最好的免费在线代理网站有哪些~急!数码资源网哪个网站可以直接在线做照片?功能要齐全的`办公协同软件免费的多人协同办公软件哪些,我了解的有钉钉、企业微信,其他的还有么?如何建立自己的网站怎么创建自己的网站硬盘人500G的硬盘容量是多少啊?雅虎天盾我机器上有瑞星杀毒和防火墙 我用雅虎天盾来查杀木马怎样?bluestackbluestacks安卓模拟器有什么用小米手柄买了个小米蓝牙手柄,游戏是可以玩但是按键位置不舒服,怎么可以改按键分词技术中文分词的应用
国外vps主机 泛域名解析 泛域名绑定 日志分析软件 http500内部服务器错误 云主机51web 青果网 元旦促销 阿里云浏览器 美国免费空间 太原网通测速平台 域名与空间 谷歌台湾 lamp怎么读 lamp兄弟连 114dns 宿迁服务器 蓝队云 月付空间 symantec 更多