如何实现GridView的手动分页.doc_第1页
如何实现GridView的手动分页.doc_第2页
如何实现GridView的手动分页.doc_第3页
如何实现GridView的手动分页.doc_第4页
如何实现GridView的手动分页.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

如何实现GridView的手动分页我们可以这样做。先要在Html界面中GridView中增加AllowPaging=True接着做下面的 /在page_load事件中将GridView绑定数据库 protectedvoidPage_Load(objectsender,EventArgse) stringsqlstr=select*fromTABLE; sqlconnectionconn=newsqlconnection(数据库连接字串); DataSetmydataset=newDataSet(); SqlDataAdaptermyds=newSqlDataAdapter(); myds.SelectCommand=newSqlCommand(sqlstr,conn); myds.Fill(mydataset); this.GridView1.DataSource=mydataset; mydataset.Dispose(); myds.Dispose(); conn.Close(); conn.Dispose(); GridView1.DataBind(); /GridView有一个PageIndexChanging事件 protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse) GridView1.PageIndex=e.NewPageIndex; GridView1.DataBind(); 这样就可以实现啦! 要使用手动分页前提是GridView没有使用数据源控件(sqldatasource.)的时候。 请教GridView的手动分页如何实现?谢谢! 请教GridView的手动分页(自定义分页)如何实现? 比如已知有10000条数据,我要GridView的分页功能来显示数据,但是自动分页功能需要每次都取出全部的10000条数据,这样效率不高, 所以就要求只用设置GridView的分页数如1000页(每页10知),当选择第n页时才从数据库中取出对应的数据,请问怎样实现? 谢谢! ASP.NET结合存储过程写的通用搜索分页程序存储过程改自bigeagle的论坛分页程序。请大家批判!:)select.aspx- protected void Page_Load(Object sender, EventArgs e) int intPageNo,intPageSize,intPageCount; intPageSize = 25; if (RequestCurrentPage=null) intPageNo = 1; else intPageNo = Int32.Parse(RequestCurrentPage); 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.Parametersa_TableList.Value = OFFERID,type,offertime; /搜索表名 workParm = mySqlCommand.Parameters.Add(a_TableName, SqlDbType.VarChar, 30); mySqlCommand.Parametersa_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.Parametersa_SelectWhere.Value = where type=idl; /表主键字段名,必须为INT类型 workParm = mySqlCommand.Parameters.Add(a_SelectOrderId, SqlDbType.VarChar, 50); mySqlCommand.Parametersa_SelectOrderId.Value = offerid; /排序,可以使用多字段排序但主键字段必需在最前面 workParm = mySqlCommand.Parameters.Add(a_SelectOrder, SqlDbType.VarChar, 50); mySqlCommand.Parametersa_SelectOrder.Value = order by offerid desc; /页号 workParm = mySqlCommand.Parameters.Add(a_intPageNo, SqlDbType.Int); mySqlCommand.Parametersa_intPageNo.Value = intPageNo; /每页显示数 workParm = mySqlCommand.Parameters.Add(a_intPageSize, SqlDbType.Int); mySqlCommand.Parametersa_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.ParametersRecordCount.Value; Int32 RowCount = (Int32)mySqlCommand.ParametersRowCount.Value; LabelRecord.Text = RecordCount.ToString(); LabelRow.Text = intPageNo.ToString(); intPageCount = RecordCount/intPageSize; if (RecordCount%intPageSize)0) intPageCount += 1; LabelPage.Text = intPageCount.ToString(); if (intPageNo1) 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 (intPageNointPageCount) 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; .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%; A:link COLOR: #cc6666 第页 | 共有页 | 条信息 | | | | 订单号 服务项目 预订日期 操作人员 分配状态 a href=javascript:void(window.open(info.asp?id=,订单分配,height=600,width=1000)订单详情 -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 int declare intEndID int declare intRootRecordCount int declare intRowCount int declare TmpSelect NVarchar(600) /*关闭计数*/ set nocount on /*求总共根贴数*/ select TmpSelect = set nocount on;select SPintRootRecordCount = count(*) from +a_TableName+ +a_SelectWhere execute sp_executesql TmpSelect, NSPintRootRecordCount int OUTPUT, SPintRootRecordCount=intRootRecordCount OUTPUTselect RecordCount = intRootRecordCount if (intRootRecordCount = 0) -如果没有贴子,则返回零 return 0 /*判断页数是否正确*/ if (a_intPageNo - 1) * a_intPageSize intRootRecordCount return (-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, NSPintRowCount int,SPintBeginID int OUTPUT, SPintRowCount=intRowCount,SPintBeginID=intBeginID OUTPUT /*结束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, NSPintRowCount int,SPintEndID int OUTPUT, SPintRowCount=intRowCount,SPintEndID=intEndID OU

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论