ASP数字分页显示代码实例

合集下载

ASP 分页显示 记录集

ASP 分页显示 记录集
<%if page<pagenum then%><a href=linkadmin.asp?page=<%=page+1%>><%end if%>下一页</a> |
<a href=linkadmin.asp?page=<%=pagenum%>>尾页</a> |
页次:<%=page%>/<%=pagenum%>页 |
If rs1.recordcount>0 Then ' 记录集不为空则处理记录
rs1.pagesize = 10 ' 设置每页显示的记录数
num=rs1.recordcount ' 记录总数
pagenum=rs1.pagecount ' 页总数
page=request("page") ' 获取页码的原始信息
%>
<!--判断当前页是否是最后一页,并根据判断设置记录的重复显示-->
<% if page<>pagenum then
lablenum=rs1.pagesize
else
lablenum=num-(page-1)*rs1.pagesize
end if
for i=1 to lablenum
</div></td>
</tr>
<%
end if
rs1.Close()
Set rs1 = Nothing
%>
好了,很简单吧!只要简单地修改一下就能插入到你的网页显示记录的地方了,赶快试试吧!
%>
<tr bgcolor="#FFFFFF">
<td height="25"><div align="center"><%=(rs1.Fields.Item("id").Value)%></div></td>

ASP 数据的分页显示

ASP  数据的分页显示

ASP 数据的分页显示
在ASP中,数据的分页显示非常实用,它的应用可以使数据表中的多条数据实现分页显示,使数据的显示更加条理清晰。

本扩展练习的目的是:使数据表messageTable中的数据实现分页显示,并实现数据的翻页功能。

(1)创建一个命名为Message.asp的ASP页面,主要实现留言内容的添加。

左键单击【文件】|【新建】命令,弹出【新建文档】对话框,在对话框的【文件类型】中选择【ASP VbScript】,【布局】中选择【无】,单击【创建】按钮。

(2)左键单击【文件】|【保存】命令,弹出另存为对话框。

在对话框的【文件名】中输入Message.asp,【保存类型】的下拉列表框中选择“Active Server Pages(*.asp;*.asa)”,单击【保存(S)】按钮。

库驱动程序,然后建立链接并查询数据返回结果集rs
(5)向ASP文件中,添加表格,并在表格中输出数据。

首先向表格中添加标
(7)关闭数据库链接,代码如下所示。

.
图9-5 分页显示。

asp分页

asp分页

<%Const maxPagesize=1000 '设置分页字数Function InsertPageBreak(strText)Dim strPagebreak,s,ssDim i,IsCount,c,iCount,strTemp,Temp_String,Temp_ArraystrPagebreak="[hiweb_break]"s=strTextIf Len(s)<maxPagesize ThenInsertPageBreak=sEnd Ifs=Replace(s, strPagebreak, "")s=Replace(s, "&nbsp;", "<&nbsp;>")s=Replace(s, "&gt;", "<&gt;>")s=Replace(s, "&lt;", "<&lt;>")s=Replace(s, """, "<">")s=Replace(s, "&#39;", "<&#39;>")If s<>"" and maxPagesize<>0 and InStr(1,s,strPagebreak)=0 thenIsCount=TrueTemp_String=""For i= 1 To Len(s)c=Mid(s,i,1)If c="<" ThenIsCount=FalseElseIf c=">" ThenIsCount=TrueElseIf IsCount=True ThenIf Abs(Asc(c))>255 TheniCount=iCount+2ElseiCount=iCount+1End IfIf iCount>=maxPagesize And i<Len(s) ThenstrTemp=Left(s,i)IfCheckPagination(strTemp,"table|a|b>|i>|strong|div|span") thenTemp_String=Temp_String & Trim(CStr(i)) & ","iCount=0End IfEnd IfEnd IfEnd IfNextIf Len(Temp_String)>1 Then Temp_String=Left(Temp_String,Len(Temp_String)-1)Temp_Array=Split(Temp_String,",")For i = UBound(Temp_Array) To LBound(Temp_Array) Step -1ss = Mid(s,Temp_Array(i)+1)If Len(ss) > 380 Thens=Left(s,Temp_Array(i)) & strPagebreak & ssElses=Left(s,Temp_Array(i)) & ssEnd IfNextEnd Ifs=Replace(s, "<&nbsp;>", "&nbsp;")s=Replace(s, "<&gt;>", "&gt;")s=Replace(s, "<&lt;>", "&lt;")s=Replace(s, "<">", """)s=Replace(s, "<&#39;>", "&#39;")InsertPageBreak=sEnd FunctionFunction CheckPagination(strTemp,strFind)Dim i,n,m_ingBeginNum,m_intEndNumDim m_strBegin,m_strEnd,FindArraystrTemp=LCase(strTemp)strFind=LCase(strFind)If strTemp<>"" and strFind<>"" thenFindArray=split(strFind,"|")For i = 0 to Ubound(FindArray)m_strBegin="<"&FindArray(i)m_strEnd ="</"&FindArray(i)n=0do while instr(n+1,strTemp,m_strBegin)<>0n=instr(n+1,strTemp,m_strBegin)m_ingBeginNum=m_ingBeginNum+1Loopn=0do while instr(n+1,strTemp,m_strEnd)<>0n=instr(n+1,strTemp,m_strEnd)m_intEndNum=m_intEndNum+1LoopIf m_intEndNum=m_ingBeginNum thenCheckPagination=TrueElseCheckPagination=FalseExit FunctionEnd IfNextElseCheckPagination=FalseEnd IfEnd FunctionFunction ContentPagination(hiwebstr)Dim ContentLen, maxperpage, PaginateDim arrContent, strContent, iDim m_strFileUrl,m_strFileExt,ArticleIDArticleID=Request.QueryString("ID")strContent = InsertPageBreak(hiwebstr)strContent = Replace(strContent, "[hiweb_break]", "[hiweb_break]")ContentLen = Len(strContent)CurrentPage=Request.QueryString("Page")If CurrentPage="" Then CurrentPage=0If InStr(strContent, "[hiweb_break]") <= 0 ThenArticleContent = "<div id=""NewsContentLabel"" class=""NewsContent"">" & strContent & "</div><div id=""Message"" class=""Message""></div>"ElsearrContent = Split(strContent, "[hiweb_break]")Paginate = UBound(arrContent) + 1If CurrentPage = 0 ThenCurrentPage = 1ElseCurrentPage = CLng(CurrentPage)End IfIf CurrentPage < 1 Then CurrentPage = 1If CurrentPage > Paginate Then CurrentPage = PaginatestrContent = "<div id=""NewsContentLabel"" class=""NewsContent"">"& arrContent(CurrentPage - 1)ArticleContent = ArticleContent & strContentIf UserArticle = True ThenArticleContent = ArticleContent & "</p></div><div id=""Message"" class=""Message""></div><p align=""center""><b>"ElseArticleContent = ArticleContent & "</p></div><p align=""center""><b>"End IfIf IsURLRewrite Thenm_strFileUrl = ArticleID & "_"Elsem_strFileExt = ""m_strFileUrl = "?id=" & ArticleID & "&Page="End IfIf CurrentPage > 1 ThenIf IsURLRewrite And (CurrentPage-1) = 1 ThenArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>上一页</a>&nbsp;&nbsp;"ElseArticleContent = ArticleContent & "<a href="""& m_strFileUrl & CurrentPage - 1 & m_strFileExt & """>上一页</a>&nbsp;&nbsp;"End IfEnd IfFor i = 1 To PaginateIf i = CurrentPage ThenArticleContent = ArticleContent & "<font color=""red"">[" & CStr(i) & "]</font>&nbsp;"ElseIf IsURLRewrite And i = 1 ThenArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>[" & i & "]</a>&nbsp;"ElseArticleContent = ArticleContent & "<a href="""& m_strFileUrl & i & m_strFileExt & """>[" & i & "]</a>&nbsp;"End ifEnd IfNextIf CurrentPage < Paginate ThenArticleContent = ArticleContent & "&nbsp;<a href="""& m_strFileUrl & CurrentPage + 1 & m_strFileExt & """>下一页</a>"End IfArticleContent = ArticleContent & "</b></p>"End IfResponse.Write(ArticleContent)End Function%>1.下载附件中的文件,将它解压上传到您的网站根目录2.在需要分页的页面最顶部调用刚刚上传的文件。

ASP.NETMVC5实现分页查询的示例代码

ASP.NETMVC5实现分页查询的示例代码

MVC5实现分页查询的⽰例代码对于⼤量数据的查询和展⽰使⽤分页是⼀种不错的选择,这篇⽂章简要介绍下⾃⼰实现分页查询的思路。

分页需要三个变量:数据总量、每页显⽰的数据条数、当前页码。

//数据总量int dataCount;//每页显⽰的数据条数int pageDataCount;int pageNumber;根据数据总量和每页显⽰的数据条数计算出总页数,根据当前页码和每页显⽰的数据条数计算出从数据库中读取数据的起始⾏号和结束⾏号。

//总页数int pageCount = (int)Math.Ceiling(dataCount/ (pageDataCount* 1.0));int startLine = (pageNumber - 1) * PageDataCount + 1;int endLine=startLine + PageDataCount - 1;对于数据库的查询操作使⽤轻量级ORM框架Dapper来实现,具体代码如下:protected IDbConnection CreateConnection(){IDbConnection dbConnection = new SqlConnection(ConnectionString);dbConnection.Open();return dbConnection;}//获取数据库中数据的总条数public virtual int QueryDataCount(string tableName){using (IDbConnection dbConnection = CreateConnection()){var queryResult = dbConnection.Query<int>("select count(Id) from " + tableName);if (queryResult == null || !queryResult.Any()){return 0;}return queryResult.First();}}public virtual IEnumerable<T> RangeQuery<T>(string tableName, int startline, int endline){if (string.IsNullOrEmpty(tableName)){throw new ArgumentNullException("表名不得为空或null");}if (startline <= 0){throw new ArgumentOutOfRangeException("起始⾏号必须⼤于0");}if (endline - startline < 0){throw new ArgumentOutOfRangeException("结束⾏号不得⼩于起始⾏号");}using (IDbConnection dbConnection = CreateConnection()){var queryResult = dbConnection.Query<T>("select top " + (endline - startline + 1) + " * from " + tableName + " where Id not in (select top " + (startline - 1) + " Id from " + tableName + " order by Id desc) order by Id desc"); if (queryResult != null && queryResult.Any()){return queryResult;}}return null;}绘制分页按钮在App_Code⽂件夹中添加PageHelper.cshtml⽂件封装绘制按钮的代码,这⾥需要注意⼀点,使⽤VS发布站点时App_Code⽂件夹中的⽂件不会被打包,需要⼿动拷贝App_Code⽂件夹中的⽂件到站点中。

ASP 分页显示数据

ASP  分页显示数据

ASP 分页显示数据ADO的Recordset对象可以容纳一个来自数据库表的记录集,并且一个Recordset对象由记录和列(字段)组成。

在练习5-1中掌握了从RecordSet对象中获取并显示数据库中的数据,而在练习5-2里学习了通过RecordSet对象修改数据的方法,本次练习仍以该对象为主。

当在数据库中存储的信息可能有成千上万条,如果一次全部显示会既耗费时间又不便于浏览。

而如果能实现数据的分页显示就能很好地解决这个问题,这也是本次练习要解决的问题,介绍怎样实现数据的分页显示。

实现思路:要想把一个记录集分成多个页进行显示,需要先使用PageSize属性指定一页中的记录个数,然后再使用AbsolutePage属性移动到一个特定的页,最后根据PageCount 属性来返回分成的总页面。

首先打开练习5-2中使用的ASP文件以ShowBookPages.asp为名进行另存。

这样,可以在检索数据库中数据的基础上进行操作,即对这些数据在RecordSet对象中进行分页并单独显示。

下面重点介绍实现代码:(1)由于本文件是基于练习5-2的,找到文件中如下的代码进行修改,使RecordSet中循环显示每一项记录,但开始之前先判断记录集中是否有数据,及总记录和当前页开始的(4)在满足了以上这些条件之后,就可以正确显示记录了,同时这里也要判断是否到(5)添加上述步骤的代码后,程序就实现了简单以每页显示5条数据进行浏览。

但是还在还不能在各个页面之间进行跳转,即翻页功能。

最后,在页面需要显示翻页的位置添加如下的实现代码:(6)保存所有步骤中所添加的代码再运行ShowBookPages.asp文件,运行后默认仅显示了5条数据,在页面底部单击“下一页”链接来查看第2页的数据,同时在底部还显示了总页数、当前页以及页的跳转链接等,如图5-5所示。

图5-5 分页显示数据效果。

用AspNetPager分页实例代码

用AspNetPager分页实例代码

很多刚学.NET的童鞋和培训学校出来的童鞋都会对数据分页而头疼,今天我把我写的一个利用AspNetPager控件分页的代码和大家分享,下面是一个类库,你直接把代码复制进去就能生成成功!using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;//添加System.Web引用using System.Web.UI.WebControls;using System.Web;//引用AspNetPager.dllnamespace Common{public class PageHelper{public PageHelper(){PageSize = 10;PageNumHtml = new System.Text.StringBuilder();UrlPageIndexName = "page";}private int _pageCount;private int _currentPageIndex;private int _recordCount;private int _pageSize;public string _urlRewritePattern;public System.Text.StringBuilder _pageNumHtml;public DataSet _dataSource;public string _customInfoHTML;public string _urlPageIndexName;public PagedDataSource Page(){PagedDataSource pagedDataSource = new PagedDataSource();pagedDataSource.DataSource =DataSource.Tables[0].DefaultView;pagedDataSource.AllowPaging = true;RecordCount = DataSource.Tables[0].Rows.Count;pagedDataSource.PageSize = PageSize;CurrentPageIndex = GetInt(UrlPageIndexName, 1);pagedDataSource.CurrentPageIndex = CurrentPageIndex - 1;int nextPageIndex = 0;int prevPageIndex = 0;int startcount = 0;int endcount = 0;if (CurrentPageIndex < 1){CurrentPageIndex = 1;}//计算总页数if (PageSize != 0){PageCount = (RecordCount / PageSize);PageCount = ((RecordCount % PageSize) != 0 ? PageCount + 1 : PageCount);PageCount = (PageCount == 0 ? 1 : PageCount);}nextPageIndex = CurrentPageIndex + 1;prevPageIndex = CurrentPageIndex - 1;startcount = (CurrentPageIndex + 5) > PageCount ? PageCount - 9 : CurrentPageIndex - 4;//中间页起始序号//中间页终止序号endcount = CurrentPageIndex < 5 ? 10 : CurrentPageIndex + 5;if (startcount < 1){startcount = 1;}//为了避免输出的时候产生负数,设置如果小于1就从序号1开始if (PageCount < endcount){endcount = PageCount;}//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内if (string.IsNullOrEmpty(CustomInfoHTML)){CustomInfoHTML = "当前页:<font color='red'><b>" + CurrentPageIndex + "</b></font>&nbsp;&nbsp;总页数:<b>" + PageCount + "</b>&nbsp;&nbsp;总记录数:<b>" + RecordCount + "</b> ";}PageNumHtml.Append(CustomInfoHTML);if (string.IsNullOrEmpty(UrlRewritePattern)){UrlRewritePattern =HttpContext.Current.Request.CurrentExecutionFilePath.Substring(1, stIndexOf(".") - 1) + "-{0}.aspx";}PageNumHtml.Append(CurrentPageIndex > 1 ? "<a href=\"" + string.Format(UrlRewritePattern, "1") + "\">首页</a> <a href=\"" + string.Format(UrlRewritePattern, prevPageIndex.ToString()) + "\">上一页</a>" : "首页上一页");//中间页处理,这个增加时间复杂度,减小空间复杂度for (int i = startcount; i <= endcount; i++){PageNumHtml.Append(CurrentPageIndex == i ? " <font color=\"#ff0000\">" + i + "</font>" : " <a href=\"" +string.Format(UrlRewritePattern, i.ToString()) + "\">" + i + "</a>"); }PageNumHtml.Append(CurrentPageIndex != PageCount ? " <a href=\"" + string.Format(UrlRewritePattern, nextPageIndex.ToString()) + "\">下一页</a> <a href=\"" + string.Format(UrlRewritePattern, PageCount) + "\">末页</a>" : " 下一页末页");return pagedDataSource;}/// <summary>/// 获得指定Url或表单参数的int类型值, 先判断Url参数是否为缺省值, 如为True则返回表单参数的值/// </summary>/// <param name="strName">Url或表单参数</param>/// <param name="defValue">缺省值</param>/// <returns>Url或表单参数的int类型值</returns>public static int GetInt(string strName, int defValue){if (GetQueryInt(strName, defValue) == defValue){return GetFormInt(strName, defValue);}else{return GetQueryInt(strName, defValue);}}/// <summary>/// 获得指定表单参数的int类型值/// </summary>/// <param name="strName">表单参数</param>/// <param name="defValue">缺省值</param>/// <returns>表单参数的int类型值</returns>public static int GetFormInt(string strName, int defValue){return StrToInt(HttpContext.Current.Request.Form[strName], defValue);}/// <summary>/// 获得指定Url参数的int类型值/// </summary>/// <param name="strName">Url参数</param>/// <param name="defValue">缺省值</param>/// <returns>Url参数的int类型值</returns>public static int GetQueryInt(string strName, int defValue){returnStrToInt(HttpContext.Current.Request.QueryString[strName], defValue); }/// <summary>/// 将对象转换为Int32类型/// </summary>/// <param name="expression">要转换的字符串</param>/// <param name="defValue">缺省值</param>/// <returns>转换后的int类型结果</returns>public static int StrToInt(object expression, int defValue) {return StrToInts(expression, defValue);}/// <summary>/// 将对象转换为Int32类型/// </summary>/// <param name="strValue">要转换的字符串</param>/// <param name="defValue">缺省值</param>/// <returns>转换后的int类型结果</returns>public static int StrToInts(object expression, int defValue) {if (expression != null){return StrToInt(expression.ToString(), defValue);}return defValue;}/// <summary>/// 总页数/// </summary>public int PageCount{get { return _pageCount; }set { _pageCount = value; }}/// <summary>/// 当前页/// </summary>public int CurrentPageIndex{get { return _currentPageIndex; }set { _currentPageIndex = value; }}/// <summary>/// 总记录数/// </summary>public int RecordCount{get { return _recordCount; }set { _recordCount = value; }}public int PageSize{get { return _pageSize; }set { _pageSize = value; }}/// <summary>/// 路径/// </summary>public string UrlRewritePattern{get { return _urlRewritePattern; }set { _urlRewritePattern = value; }}public System.Text.StringBuilder PageNumHtml {get { return _pageNumHtml; }set { _pageNumHtml = value; }}/// <summary>/// 数据源/// </summary>public DataSet DataSource{get { return _dataSource; }set { _dataSource = value; }}public string CustomInfoHTML{get { return _customInfoHTML; }set { _customInfoHTML = value; }}public string UrlPageIndexName{get { return _urlPageIndexName; }set { _urlPageIndexName = value; }}/// <summary>/// 分页/// </summary>/// <param name="dataTable">数据源</param>/// <param name="pageSize">每页多少条</param>/// <param name="currentPageIndex">当前页</param>/// <param name="pager"></param>public PagedDataSource PageDataSource(DataTable dataTable, int pageSize, int currentPageIndex, Wuqi.Webdiyer.AspNetPager pager){DataView dataView = dataTable.DefaultView;string sortExpression =HttpContext.Current.Request["sortExpression"];string sortDirection =HttpContext.Current.Request["sortDirection"];if ((!string.IsNullOrEmpty(sortExpression)) &&(!string.IsNullOrEmpty(sortDirection))){dataView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);}PagedDataSource myPage = new PagedDataSource();myPage.DataSource = dataView;pager.RecordCount = dataTable.Rows.Count;myPage.AllowPaging = true;myPage.PageSize = pageSize;pager.PageSize = myPage.PageSize;pager.UrlPaging = true;pager.FirstPageText = "首页";pager.PrevPageText = "上一页";pager.NextPageText = "下一页";stPageText = "尾页";myPage.CurrentPageIndex = currentPageIndex - 1;return myPage;}}}准备的东西都做完了,那我们看一下在页面的后台我们该怎么去写呢?在页面的后台只需要写几行代码即可,实例代码如下:DataTable dt = 绑定的数据集;int currentPageIndex = Common.PageHelper.GetQueryInt("page", 1);得到当前页rep_pro.DataSource = newCommon.PageHelper().PageDataSource(dt, this.pages.PageSize, currentPageIndex, pages);rep_pro.DataBind();。

ASP分页代码详解

ASP分页代码详解
<%end if%><%if rs.pagecount<curpage+1 then%>下一页<%else%><a href="?curpage=<%=curpage+1%>">下一页</a><%end if%><%if rs.pagecount<curpage+1 then%>尾页<%else%><a href="?curpage=<%=rs.pagecount%>">尾页</a> '尾页则是将rs.pagecount这个是记录集分页的总数这样就是尾页了
IF rs.eof or rs.bof Then ' 这里我们判断记录集是否为空,以防出错
response.write("暂无产品") '输出记录集为空时的内容
Else ' 如果记录集不为空则
rs.pagesize=30 '定义每页显示记录30条
<%end if%>
当前第<span class="red"><%=curpage%></span>页 '这里就是用curpage的变量实现当前第几页
共有<span class="red"><%=rs.pagecount%></span>页 '这个就是用rs.pagecount属性来实现共有多少页
curpage=request.QueryString("curpage") '获取地址栏curpage的值

ASP分页代码

ASP分页代码

ASP分页代码<!-- #i nclude file="../conn.asp" --> //(Yoko:路径按自己的设置好)<%dim i,intPage,page,pre,last,filepathset rs = server.CreateObject("adodb.recordset")sql="select * from user order by user_ID desc"rs.PageSize = 20 //(Yoko:这里设定每页显示的记录数rs.CursorLocation = 3rs.Open sql,conn,0,2,1 //(Yoko:'这里执行你查询SQL并获得结果记录集pre = truelast = truepage = trim(Request.QueryString("page"))if len(page) = 0 thenintpage = 1pre = falseelseif cint(page) =< 1 thenintpage = 1pre = falseelseif cint(page) >= rs.PageCount thenintpage = rs.PageCountlast = falseelseintpage = cint(page)end ifend ifend ifif not rs.eof thenrs.AbsolutePage = intpageend if%><!--循环开始--><%for i=1 to rs.PageSizeif rs.EOF or rs.BOF then exit for%>..................//(Yoko:要循环显示的内容).....................................<%rs.movenextnext%><!--循环体结束分页部分:--><table width="99%" border="1" cellpadding="2" cellspacing="2" borderColorLi ght=#808080 borderColorDark=#ffffff><tr><%if rs.pagecount > 0 then%><td width="13%" align="left">当前页<%=intpage%>/<%=rs.PageCount%> </td><%else%><td width="41%" align="left">当前页0/0</td><%end if%><td width="46%" align="right"> <a href="本页.asp?page=1">首页</a>| <%if pre then%><a href="本页.asp?page=<%=intpage -1%>">上页</a>| <%end if%><%if last then%><a href="本页.asp?page=<%=intpage +1%>">下页</a> |<%end if%><a href="本页.asp?page=<%=rs.PageCount%>">尾页</a>|转到第<select name="sel_page" onchange="javascript:location=this.options[this.s electedIndex].value;"><%for i = 1 to rs.PageCountif i = intpage then%><option value="本页.asp?page=<%=i%>" selected><%=i%></option> <%else%><option value="本页.asp?page=<%=i%>"><%=i%></option><%end ifnext%></select>页</font></td></table>下面是CSDN的:<%dim Conn,RS,sqlStr,PageSize,RowCount,TotalPages,PageNo,Position,PageB egin,PageEndset Conn= Server.CreateObject("ADODB.Connection")set RS = Server.CreateObject("ADODB.RecordSet")Conn.open "provider=sqloledb;data source=127.0.0.1;user id=sa;passwo rd=;initial catalog=zjydata"sqlStr="select * from Items order by iID"RS.open sqlStr,Conn,1,1PageSize=10If RS.RecordCount=0 then%><TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACIN G=1 style='font-size:9pt'><TR bgcolor=#003366 height=20px><TD align=center><font color=#FFFFFF>商品代码</font></TD><TD align=center><font color=#FFFFFF>商品名称</font></TD><TD align=center><font color=#FFFFFF>型号规格</font></TD><TD align=center><font color=#FFFFFF>计量单位</font></TD><TD align=center><font color=#FFFFFF>参考进价</font></TD><TD align=center><font color=#FFFFFF>参考售价</font></TD><TD align=center><font color=#FFFFFF>备注</font></TR><TR height=20px><TD align=center>没有任何商品信息!</TD><TR></TABLE>elseRS.PageSize = Cint(PageSize)TotalPages=RS.PageCountPageNo=Request.QueryString("PageNo")if PageNo="" or PageNo<1 ThenPageNo = 1end ifRS.AbsolutePage = PageNoPosition=RS.PageSize*PageNoPageBegin=Position-RS.PageSize+1if Position <RS.RecordCount thenPageEnd=PositionelsePageEnd= RS.RecordCountend if%><TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACIN G=1 style='font-size:9pt'><TR><TD width=20%><%Response.Write "页:"& PageNo &" / "& TotalPages &" | 记录:"& PageBegin & " - " & PageEnd & " / " &RS.RecordCount%></TD><TD align=right><%if PageNo > 1 Thenresponse.write "<a href=list.asp?PageNo=1>首页</a> &nbsp;<a href=list.asp?PageNo=" & (PageNo-1) & ">上页</a>&nbsp;"end ifif TotalPages > 1 and cint(PageNo) <> cint(TotalPages) th enresponse.write "<a href=list.asp?PageNo=" & (PageNo +1) & ">下页</a>&nbsp;<a href=list.asp?PageNo=" & TotalPages & ">末页</ a>&nbsp;"end if%></TD></TR><TR bgcolor=#003366 height=20px><TD align=center width=20%><font color=#FFFFFF>商品代码</fo nt></TD><TD align=center width=30%><font color=#FFFFFF>商品名称</fo nt></TD><TD align=center width=8%><font color=#FFFFFF>型号规格</fon t></TD><TD align=center width=8%><font color=#FFFFFF>计量单位</fon t></TD><TD align=center width=8%><font color=#FFFFFF>参考进价</fon t></TD><TD align=center width=8%><font color=#FFFFFF>参考售价</fon t></TD><TD align=center width=18%><font color=#FFFFFF>备注</font> </TR><%RowCount = RS.PageSizedim color1,color2color1="#dddddd"color2="#eeeeee"Do While Not RS.EOF and RowCount > 0Response.Write "<TR height=20px bgcolor="%><%if RowCount mod 2=0 then:response.write color1 else:respo nse.write color2%><%Response.Write ">"%><TD><span><a href=manage.asp?id=<%=rs(0)%>><% =RS("v Code")%></a></span></td><TD><span><% =RS("vName")%></span></td><TD><span><% =RS("vSpec")%></span></TD><TD><span><% =RS("vUnit")%></span></td><TD><span><% =RS("fInPrice")%></span></td><TD><span><% =RS("fOutPrice")%></span></TD><TD><span><% =RS("vDescription")%></span></td></TR><%RowCount = RowCount - 1RS.MoveNextLoopConn.Closeset RS = nothingset Conn = nothing%><TR bgcolor=#003366 height=20px><TD align=center width=20%><font color=#FFFFFF>商品代码</fo nt></TD><TD align=center width=30%><font color=#FFFFFF>商品名称</fo nt></TD><TD align=center width=8%><font color=#FFFFFF>型号规格</fon t></TD><TD align=center width=8%><font color=#FFFFFF>计量单位</fon t></TD><TD align=center width=8%><font color=#FFFFFF>参考进价</fon t></TD><TD align=center width=8%><font color=#FFFFFF>参考售价</fon t></TD><TD align=center width=18%><font color=#FFFFFF>备注</font></TR><TR><TD><%For i=1 to TotalPagesif CInt(PageNo) = CInt(i) thenresponse.write "["&i&"]"elseresponse.write "&nbsp<a href=list.asp?PageNo ="&i&">"&i&"</a>&nbsp"end ifNext%></TD></TR></TABLE><%End if%>。

asp网站实现AJAX数据查询并分页显示

asp网站实现AJAX数据查询并分页显示

ASP网站通过AJAX查询数据并分页显示,根据一些教程中的分页显示代码,增加了动态查询功能,同时将查询结果生成EXCEL文件供用户下载。

一、显示页面代码:<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><style type="text/css">body,html,div,p,form,h1,h2,h3,h4,h5,hr{ margin:0; padding:0;font-size:14px;}div#contain{width:80%; margin:0 auto;}table{ text-align:center; border-collapse:collapse; width:100%;}tr.tr1{ background-color:#555; color:#FFF; height:24px; line-height:24px;}p{ margin-bottom:10px;}a.a_page{padding-right:10px; padding-left:10px; border-right:2px solid #EEE; text-decoration:none; color:#FFF;}a.a_page:hover{ color:#F03;}a.a_page_n{padding-right:10px; padding-left:10px; border-right:2px solid #EEE; text-decoration:none; color:#888;}.iframe1{ overflow:hidden; width:100%; }</style><script type="text/javascript">// 查询与分页记录集函数,通过传递两个参数来查询ajax数据,实现查询分页,其中str 为搜索数据,y为记录集页function FF(str,y){var xmlhttp;if (str==""){document.getElementById("txtHint").innerHTML="";return;}if (!y) {y=1;}if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safarixmlhttp=new XMLHttpRequest();}else{// code for IE6, IE5xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){document.getElementById("txtHint").innerHTML=xmlhttp.responseText;}}xmlhttp.open("GET","getorder_list.asp?q="+str+"&page="+y,true);xmlhttp.send();}</script></head><body><div id="contain"><%set conn=server.CreateObject("ADODB.Connection")conn.open "provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database password=ldlt2015;data source=d:\database\customer_care.mdb;"v_year = year(date())v_month = month(date())v_day = day(date())'月份计算if v_month < 12 thenv_next_m = v_month + 1elsev_next_m = 1end ifset rs=server.CreateObject("ADODB.Recordset")sql = "SELECT * from order_list"rs.open sql,conn%><form action="" style="margin-top:15px;"><label><p><select name="customers" onchange="showCustomer(this.value)" style="font-family:Verdana, Arial, Helvetica, sans-serif;"><option value="" selected="selected">选择月份</option><option value="2">201602</option><option value="3">201603</option></select></p></label></form><hr /><div id="txtHint"></div><hr /><iframe src="order_scan_img.asp" width="100%" height="500" frameborder="0" name="order_img" class="iframe1"></iframe></div></body></html>二、AJAX查询代码:<%response.expires=-1order_month = request.QueryString("q")set conn=server.CreateObject("ADODB.Connection")conn.open "provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database password=ldlt2015;data source=d:\database\customer_care.mdb;"v_year = year(date())v_month = month(date())v_day = day(date())'月份计算if v_month < 12 thenv_next_m = v_month + 1elsev_next_m = 1end ifSet fs = server.CreateObject("scripting.filesystemobject")'--假设你想让生成的EXCEL文件做如下的存放filename = Server.MapPath("files\order_list.xls")'--如果原来的EXCEL文件存在的话删除它if fs.FileExists(filename) thenfs.DeleteFile(filename)end if'--创建EXCEL文件set myfile = fs.CreateTextFile(filename,true)set rs=server.CreateObject("ADODB.Recordset")sql = "select * from order_list where order_month = "&order_month&" and order_status = 1"rs.pagesize = 10rs.cursorlocation = 3rs.open sql,conn,1,1pre = truelast = truepage=clng(request.QueryString("page"))if page<1 then page=1if page>rs.pagecount then page=rs.pagecountrs.absolutepage=pageresponse.Charset = ("GB2312") '转换编码,防止中文在输出页面变成乱码response.Write("<table width='100%' align='center' border='1'>")response.Write("<tr class='tr1'>")response.Write("<td width='6%'>月份</td>")response.Write("<td width='6%'>区县</td>")response.Write("<td width='25%'>渠道</td>")response.Write("<td width='10%'>渠道账号</td>")response.Write("<td width='15%'>订购任务</td>")response.Write("<td width='15%'>已完成</td>")response.Write("<td width='13%'>欠产</td>")response.Write("<td width='10%'>协议书</td>")response.Write("</tr>")for i = 1 to rs.pagesizeif rs.eof or rs.bof then exit forresponse.Write("<tr>")response.Write("<td>"& rs.fields("order_month") &"</td>")response.Write("<td>"& rs.fields("district") &"</td>")response.Write("<td>"& rs.fields("c_user") &"</td>")response.Write("<td>"& rs.fields("c_count") &"</td>")response.Write("<td>"& rs.fields("order_nums") &"</td>")response.Write("<td>"& rs.fields("n_nums") &"</td>")response.Write("<td>"& rs.fields("order_nums")-rs.fields("n_nums") &"</td>")response.Write("<td><a href='order_scan_img.asp?img="& rs.fields("uploadpath") &"' target='order_img'>查看协议书</a></td>")response.Write("</tr>")rs.movenextnextresponse.Write("<tr class='tr1'>")response.Write("<td colspan='8'>")if page=1 thenresponse.write("<a href='javascript:void(0)' class='a_page_n'>首页</a><a href='javascript:void(0)' class='a_page_n'>上一页</a>")response.write("<a href='javascript:FF("&order_month&","&(page+1)&")' class='a_page'>"&"下一页"&"</a>")response.write("<a href='javascript:FF("&order_month&","&rs.pagecount&")' class='a_page'>"&"未页"&"</a>")elseif page=rs.pagecount thenresponse.write("<a href='javascript:FF("&order_month&",1)' class='a_page'>"&"首页"&"</a>")response.write("<a href='javascript:FF("&order_month&","&(page-1)&")' class='a_page'>"&"上一页"&"</a>")response.write("<a href='javascript:void(0)' class='a_page_n'>下一页</a><a href='javascript:void(0)' class='a_page_n'>未页</a>")elseresponse.write("<a href='javascript:FF("&order_month&",1)' class='a_page'>"&"首页"&"</a>")response.write("<a href='javascript:FF("&order_month&","&(page-1)&")' class='a_page'>"&"上一页"&"</a>")response.write("<a href='javascript:FF("&order_month&","&(page+1)&")' class='a_page'>"&"下一页"&"</a>")response.write("<a href='javascript:FF("&order_month&","&rs.pagecount&")' class='a_page'>"&"未页"&"</a>")end ifresponse.Write("</td>")response.Write("</tr>")response.Write("</table>")if rs.recordcount <> 0 thenstrSql = "select id as 编号,district as 业务单元,c_user as 渠道,order_nums as 认购任务,n_nums as 已完成from order_list where order_month = "&order_month&" and order_status = 1"Set rstData =conn.execute(strSql)if not rstData.EOF and not rstData.BOF thendim trLine,responsestrstrLine=""For each x in rstData.fieldsstrLine = strLine & & chr(9)Next'--将表的列名先写入EXCELmyfile.writeline strLineDo while Not rstData.EOFstrLine=""for each x in rstData.FieldsstrLine = strLine & x.value & chr(9)nextmyfile.writeline strLinerstData.MoveNextloopend ifresponse.Write("<p>查询数据结果EXCEL文件创建成功,点击---><a href='files/order_list.xls' target='_blank'>下载</a></p>")response.Write("<form action='order_check.asp' method='post' enctype='multipart/form-data' >")response.Write("<div class='p1'>选择文件:<input type='file' name='upfile' class='file_1' /><input type='submit' value=' 确定' /></div></form>")end if%>。

用ASP实现长文章用分页符来分页显示

用ASP实现长文章用分页符来分页显示

用ASP实现长文章用分页符来分页显示长文章页用分页符来显示,想用ASP也实现这种功能,可发现只有根据字数进行分页的方法,但这种方法有一个BUG,就是如果你文章内容中如果有UBB代码,它很容易造成在[code][/code]之间进行分页,或者干脆就把[code]分解成了[co和de],这样文章显示就会出现错误。

以下几个步骤将能够完全实现。

第一步:按照正常的文章系统一路做下去,后台的文章添加,文章的检索,和文章的详细页,都是常规方式操作,这里不加描述,请参阅相关帖子。

只是在文章添加时,在你想让它分页的地方加上分页符:“|||”(当然这个符号你可以随便用,比如:[page]、&&&、###、@@@……,只要它不会在文章要正常显示的地方出现就行了。

)我用了四个页面,输入页(index.asp)、输入完成页(add.asp)、文章列表页(view.asp)、文章内容页(display.asp),前三个都是不用处理的页面,看下面的图片我想一般的小鸟就会做了,关键是最后一个displasy.asp,所有实现分页的代码都在这里。

第二步:在文章正文内容的动态数据部分做一些手脚,下面是代码和解释:<%'这里要处理接收到的分页参数,以此来进行显示第几页的内容'下面这两句就是如果没有page这个参数传来就让变量pageNum取显示第一页的值:0If Request("page")="" ThenpageNum=0'否则就给变量赋值为传递来的page里的参数,来显示其他页ElsepageNum=Request("page")End if%><%'如果加了可选执行UBB代码,可以加上下面的代码'rs("NoUBB")是数据库里关于禁用UBB的字段,0为禁用,1为执行If rs("NoUBB")=0 then'为避免和文章内容相连出现错误,用Replace函数把分页代码“|||”的前后各加一个全角的'rs("content")是数据库里正文的字段,在这里加上UBB或者禁用UBBContent=Replace((unHTML(rs("content"))),"|||","|||")Elseif rs("NoUBB")=1 thenContent=Replace((ubb(rs("content"))),"|||","|||")End if%><%'这里就是关键了'我们用split函数将文章分段取出存入变量contentContentStr=split(Content,"|||")'按照刚才从URL参数中取得的要显示那面的那个变量,就循环显示一页For i=pageNum to pageNum%><!--这里将是文章正文内容--><%=ContentStr %><% Next %></td></tr><tr><td height="30" class="ClassName">本文共分<%'分页的地方,用ubound(ContentStr)取得文章一共分为几页,注意这里是从0开始,所以总页数需要加1For p = 0 to ubound(ContentStr)'链接还是本页面,只不过文章ID参数后面还要加上一个分页的参数:page%><a href="display.asp?ID=<%=rsquest("ID")%>&page=<%=p%>" class=""><%=p+1%></a><% Next %>页很简单吧,要是把注释都删除,才15行代码,不过还要加工一下,让它能有上一页、下一页和当前页突出的功能就完善了。

Asp.Net中的三种分页方式总结

Asp.Net中的三种分页方式总结

中的三种分页⽅式总结通常分页有3种⽅法,分别是⾃带的数据显⽰空间如GridView等⾃带的分页,第三⽅分页控件如aspnetpager,存储过程分页等。

这⾥分别做总结。

第⼀种:使⽤GridView⾃带分页,这种是最简单的分页⽅法。

前台的⽅法:复制代码代码如下:<asp:GridView ID="GridView1" AllowPaging="true" runat="server"onpageindexchanging="GridView1_PageIndexChanging" PageSize="3"></asp:GridView>后台⽅法:代码复制代码代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using JXSoft.TicketManage.Model;using JXSoft.TicketManage.BLL;using System.Text.RegularExpressions;using System.Data;namespace JXSoft.TicketManage.Web{public partial class Test : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){if(!IsPostBack){BindData();}}protected void BindData(){DataTable dt=new DataTable();dt.Columns.Add("ID");dt.Columns.Add("Name");for (int i = 0; i < 10;i++ ){dt.Rows.Add(i.ToString(), i.ToString());}this.GridView1.DataSource = dt;this.GridView1.DataBind();}protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e){this.GridView1.PageIndex = e.NewPageIndex;BindData();}}}第⼆种:使⽤个性化显⽰的AspNetPager.dll进⾏分页此处需要添加aspnetpager.dll的引⽤前台:复制代码代码如下:<form id="form1" runat="server"><div><asp:GridView ID="GridView1" runat="server" ></asp:GridView><webdiyer:AspNetPager ID="AspNetPager1" runat="server"CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条"FirstPageText="⾸页" LastPageText="尾页" LayoutType="Table" NextPageText="下⼀页"onpagechanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList"PagingButtonLayoutType="Span" PrevPageText="上⼀页" ShowCustomInfoSection="Left"ShowPageIndexBox="Always" SubmitButtonText="Go" PageSize="4" TextAfterPageIndexBox="页"TextBeforePageIndexBox="转到"></webdiyer:AspNetPager></div></form>后台:复制代码代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using JXSoft.TicketManage.Model;using JXSoft.TicketManage.BLL;using System.Text.RegularExpressions;using System.Data;namespace JXSoft.TicketManage.Web{public partial class Test : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){if(!IsPostBack){BindData();}}protected void BindData(){DataTable dt=new DataTable();dt.Columns.Add("ID");dt.Columns.Add("Name");for (int i = 0; i < 10;i++ ){dt.Rows.Add(i.ToString(), i.ToString());}DataSet ds = new DataSet();ds.Tables.Add(dt);Pager(this.GridView1, this.AspNetPager1, ds);}protected void Pager(GridView dl, Wuqi.Webdiyer.AspNetPager anp, System.Data.DataSet dst){PagedDataSource pds = new PagedDataSource();pds.DataSource = dst.Tables[0].DefaultView;pds.AllowPaging = true;anp.RecordCount = dst.Tables[0].DefaultView.Count;pds.CurrentPageIndex = anp.CurrentPageIndex - 1;pds.PageSize = anp.PageSize;dl.DataSource = pds;dl.DataBind();}protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e){AspNetPager1.CurrentPageIndex = e.NewPageIndex;BindData();}}}第三种:使⽤AspNetPager结合存储过程进⾏分页这种⽅法分页稍微复杂⼀些,但是可以应付⽐较⼤的数据量。

asp分页程序代码简介

asp分页程序代码简介
asp 分页程序代码简介
欢迎大家在这里学习 asp 分页程序代码!这里是我们给大家整理出来的精 彩内容。我相信,这些问题也肯定是很多朋友在关心的,所以我就给大家谈 谈这个! Set rs=Server.Createobject(“ADODB.RECORDSET”) rs.Open sql, conn, 1, 1 if not rs.eof then pages = 30 ‘定义每页显示的记录数 rs.pageSize = pages ‘定义每页显示的记录数 allPages = rs.pageCount’计算一共能分多少页 page = Request.QueryString(“page”)’通过浏览器传递的页数 ‘if 语句属于基本的排错处理 if isEmpty(page) or Cint(page) page = 1
elseif Cint(page) >; allPages then page = allPages end if rs.AbsolutePage = page Do while not rs.eof and pages >; 0 %>; 这里输出你要的内容 rs.MoveNext Loop else Response.Write(“数据库暂无内容!”) End if rs.Close Set rs = Nothing %>;
好了,asp 分页程序代码内容就给大家介绍到这里了。希

ASP如何实现SQL Server的分页显示?

ASP如何实现SQL Server的分页显示?

如何实现SQL Server的分页显示?分页显示是页面常用技术,可用下列代码来实现:<%page=Request.QueryString("page")' 取page值Set conn=Server.CreateObject("ADODB.Connection")sql="select * from table"Set rs=conn.Execute(sql)' 在数据库中进行查询rs.PageSize=30' 设置分的页数,设好后系统会自动将rs.PageCount计算出来If Page&lt1 Then Page=1If Page=null Then Page=1If Page&gtrs.PageCount Then Page=rs.PageCount' rs.PageCount是总页数rs.AbsolutePage=page' 将要显示的页数If page<&gt1 ThenResponse.Write"&lta href=show.asp?page=1>第一页</a>" Response.Write"&lta href=show.asp?page="&(page-1)前一页</a>"End IfIf page<&gtrs.PageCount ThenResponse.Write"&lta href=show.asp?page="&(page+1)>后一页</a>" Response.Write"&lta href=show.asp?page="&rs.PageCount>最末页</a>" End IfFor iPage=1 To rs.PageSize' 显示分页%><%=rs("显示字段")%><%rs.MoveNext' 若到尾部则跳出If rs.EOF Then Exit For Next%>。

完美的ASP分页脚本代码

完美的ASP分页脚本代码

完美的ASP分页脚本代码直接写成函数的形式,如果输出⽣成好的页码,然后⼜程序输出或保存到⽂件中。

前⼗页为⼀批,第⼗页显⽰1,2,3...10;第⼗⼀页页码就变成了11,12 (20)这种模式很多CMS都⽤到,⽐如5UCMS。

函数名留点版权信息吧,cs=CatSeven<%function csPage(id,all,url1,url2)if id<>1 then tmp="<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow istart=((id-1)\10)*10+1if(all-id)>9 theniend=((id-1)\10)*10+10elseiend=allend iffor i=istart to iendif i=id thentmp=tmp&"<span>"&i&"</span> "elsetmp=tmp&"<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel=" end ifnextif id<>all then tmp=tmp&"<a href=""" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external no csPage=tmpend function'DEBUGfor j=1 to 40response.write "#Page"&j&":"&csPage(j,40,"#TEST_","_View")&"<br />"next%>⽣成效果如下:#Page1:1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page2:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page3:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page4:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page5:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page6:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page7:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page8:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page9:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page10:⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 下⼀页尾页#Page11:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page12:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page13:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page14:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page15:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page16:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page17:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page18:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page19:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page20:⾸页上⼀页 11 12 13 14 15 16 17 18 19 20 下⼀页尾页#Page21:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page22:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page23:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page24:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page25:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page26:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page27:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page28:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page29:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page30:⾸页上⼀页 21 22 23 24 25 26 27 28 29 30 下⼀页尾页#Page31:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page32:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page33:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page34:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page35:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page36:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page37:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page38:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page39:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40 下⼀页尾页#Page40:⾸页上⼀页 31 32 33 34 35 36 37 38 39 40说实话我并不是很喜欢这种分页⽅式,我⽐较喜欢上次写的那个。

ASP分页源码

ASP分页源码

<%'==================================================================='XDOWNPAGE ASP版本'版本 1.00'Code by zykj2000'Email: zykj_2000@'BBS: '本程序可以免费使用、修改,希望我的程序能为您的工作带来方便'但请保留以上请息''程序特点'本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义,'支持URL多个参数''使用说明'程序参数说明'PapgeSize 定义分页每一页的记录数'GetRS 返回经过分页的Recordset此属性只读'GetConn 得到数据库连接'GetSQL 得到查询语句'程序方法说明'ShowPage 显示分页导航条,唯一的公用方法''===================================================================Const Btn_First="<font face=""webdings"">9</font>" '定义第一页按钮显示样式Const Btn_Prev="<font face=""webdings"">3</font>" '定义前一页按钮显示样式Const Btn_Next="<font face=""webdings"">4</font>" '定义下一页按钮显示样式Const Btn_Last="<font face=""webdings"">:</font>" '定义最后一页按钮显示样式Const XD_Align="Center" '定义分页信息对齐方式Const XD_Width="100%" '定义分页信息框大小Class XdownpagePrivateXD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int _totalPage,int_totalRecord,XD_sURL'================================================================='PageSize 属性'设置每一页的分页大小'=================================================================Public Property Let PageSize(int_PageSize)If IsNumeric(Int_Pagesize) ThenXD_PageSize=CLng(int_PageSize)Elsestr_error=str_error & "PageSize的参数不正确"ShowError()End IfEnd PropertyPublic Property Get PageSizeIf XD_PageSize="" or (not(IsNumeric(XD_PageSize))) ThenPageSize=10ElsePageSize=XD_PageSizeEnd IfEnd Property'================================================================= 'GetRS 属性'返回分页后的记录集'================================================================= Public Property Get GetRs()Set XD_Rs=Server.createobject("adodb.recordset")XD_Rs.PageSize=PageSizeXD_Rs.Open XD_SQL,XD_Conn,1,1If not(XD_Rs.eof and XD_RS.BOF) ThenIf int_curpage>XD_RS.PageCount Thenint_curpage=XD_RS.PageCountEnd IfXD_Rs.AbsolutePage=int_curpageEnd IfSet GetRs=XD_RSEnd Property'================================================================ 'GetConn 得到数据库连接''================================================================ Public Property Let GetConn(obj_Conn)Set XD_Conn=obj_ConnEnd Property'================================================================ 'GetSQL 得到查询语句''================================================================ Public Property Let GetSQL(str_sql)XD_SQL=str_sqlEnd Property'================================================================== 'Class_Initialize 类的初始化'初始化当前页的值''================================================================== Private Sub Class_Initialize'========================'设定一些参数的黙认值'========================XD_PageSize=10 '设定分页的默认值为10'========================'获取当前面的值'========================If request("page")="" Thenint_curpage=1ElseIf not(IsNumeric(request("page"))) Thenint_curpage=1ElseIf CInt(Trim(request("page")))<1 Thenint_curpage=1ElseInt_curpage=CInt(Trim(request("page")))End IfEnd Sub'==================================================================== 'ShowPage 创建分页导航条'有首页、前一页、下一页、末页、还有数字导航''==================================================================== Public Sub ShowPage()Dim str_tmpXD_sURL = GetUrl()int_totalRecord=XD_RS.RecordCountIf int_totalRecord<=0 Thenstr_error=str_error & "总记录数为零,请输入数据"Call ShowError()End IfIf int_totalRecord="" thenint_TotalPage=1ElseIf int_totalRecord mod PageSize =0 Thenint_TotalPage = CLng(int_TotalRecord / XD_PageSize * -1)*-1Elseint_TotalPage = CLng(int_TotalRecord / XD_PageSize * -1)*-1+1End IfEnd IfIf Int_curpage>int_Totalpage Thenint_curpage=int_TotalPageEnd If'=================================================================='显示分页信息,各个模块根据自己要求更改显求位置'==================================================================response.write ""str_tmp=ShowFirstPrvresponse.write str_tmpstr_tmp=showNumBtnresponse.write str_tmpstr_tmp=ShowNextLastresponse.write str_tmpstr_tmp=ShowPageInforesponse.write str_tmpresponse.write ""End Sub'===================================================================='ShowFirstPrv 显示首页、前一页'''====================================================================Private Function ShowFirstPrv()Dim Str_tmp,int_prvpageIf int_curpage=1 Thenstr_tmp=Btn_First&" "&Btn_PrevElseint_prvpage=int_curpage-1str_tmp="<a href="""&XD_sURL & "1" & """>" & Btn_First&"</a> <a href=""" & XD_sURL & CStr(int_prvpage) & """>" & Btn_Prev&"</a>"End IfEnd Function'===================================================================='ShowNextLast 下一页、末页'''====================================================================Private Function ShowNextLast()Dim str_tmp,int_NextpageIf Int_curpage>=int_totalpage Thenstr_tmp=Btn_Next & " " & Btn_LastElseInt_NextPage=int_curpage+1str_tmp="<a href=""" & XD_sURL & CStr(int_nextpage) & """>" & Btn_Next&"</a> <a href="""& XD_sURL & CStr(int_totalpage) & """>" & Btn_Last&"</a>"End IfShowNextLast=str_tmpEnd Function'===================================================================='ShowNumBtn 数字导航'''====================================================================Private Function showNumBtn()Dim i,str_tmpFor i=1 to int_totalpagestr_tmp=str_tmp & "[<a href=""" & XD_sURL & CStr(i) & """>"&i&"</a>] "NextshowNumBtn=str_tmpEnd Function'===================================================================='ShowPageInfo 分页信息'更据要求自行修改''====================================================================Private Function ShowPageInfo()Dim str_tmpstr_tmp="页次:"&int_curpage&"/"&int_totalpage&"页共"&int_totalrecord&"条记录"&XD_PageSize&"条/每页"End Function'================================================================== 'GetURL 得到当前的URL'更据URL参数不同,获取不同的结果''================================================================== Private Function GetURL()Dim strurl,str_url,i,j,search_str,result_urlsearch_str="page="strurl=Request.ServerVariables("URL")Strurl=split(strurl,"/")i=UBound(strurl,1)str_url=strurl(i)'得到当前页文件名str_params=Trim(Request.ServerVariables("QUERY_STRING"))If str_params="" Thenresult_url=str_url & "?page="ElseIf InstrRev(str_params,search_str)=0 Thenresult_url=str_url & "?" & str_params &"&page="Elsej=InstrRev(str_params,search_str)-2If j=-1 Thenresult_url=str_url & "?page="Elsestr_params=Left(str_params,j)result_url=str_url & "?" & str_params &"&page="End IfEnd IfEnd IfGetURL=result_urlEnd Function'==================================================================== ' 设置 Terminate 事件。

asp.net文章内容分页代码

asp.net文章内容分页代码

⽂章内容分页代码今天刚做完的⼀个⽂章内容分页,主要原理是插⼊特殊字符,然后根据特殊字符进⾏字符串分解。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web;namespace ZS.BLL{public class Pager{public static string ContentPage(string content,int page){string[] array_content = content.Split(new string[] { "{$:page}" }, StringSplitOptions.None);int length = array_content.Length;if (length <= 1){return content;}return array_content[page - 1] + MakePage(length,page);}public static string MakePage(int length,int page){string url;int ic = HttpContext.Current.Request.RawUrl.IndexOf("&page");if (ic > 0){url = HttpContext.Current.Request.RawUrl.Remove(ic);}else{url = HttpContext.Current.Request.RawUrl;}StringBuilder builder = new StringBuilder();builder.Append("<table id=\"pagelist\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">");builder.Append("<tr><td align=\"center\"><ul><li><a href=\"" + url + "\">⾸页</a></li><li><a href=\"" + url + "&page=" + (page -1).ToString() + "\">上⼀页</a></li>");for (int i = 0; i < length; i++){if (page - 1 == i){builder.Append("<li class=\"current\">" + (i + 1).ToString() + "</li>");}else{builder.Append("<li><a href=\"" + url + "&page=" + (i + 1).ToString() + "\">" + (i + 1).ToString() + "</a></li>");}}if (page < length){builder.Append("<li><a href=\"" + url + "&page=" + (page + 1).ToString() + "\">下⼀页</a></li>");}else{builder.Append("<li><a href=\"" + url + "&page=" + page.ToString() + "\">下⼀页</a></li>");}builder.Append("<li><a href=\"" + url + "&page=" + length.ToString() + "\">尾页</a></li></ul></td></tr></table>");return builder.ToString();}}}。

ASP.NET中DataList数字分页代码

ASP.NET中DataList数字分页代码

中DataList数字分页代码好长时间没发东西了, 之前⼀段时间⼀直在做别的东西, 最近java实验室要开搞系统哈哈, 重新学习.net这个分页困扰了我这个菜鸟好久阿, 搞了好久终于找到这段代码, 还是数字分页, 试了成功了~还不会分页的朋友看到这个就偷笑吧~~效果:共1页⾸页上⼀页 1 2 3 4 5 6 7 8 9 10 ....下⼀页末页调⽤页⾯(Aspx):在要显⽰分页导航的地⽅加个DIV标签:<div id="PageInfo" runat="server"></div>调⽤页的代码(CS):DataSet ds = db.getDs(sql);this.PageInfo.InnerHtml = PageNums.GetPageNum(ds,DataList1,12); //传⼊DataSet,DataList名称和分页⼤⼩PageNums实现分页类(PageNums.cs):下⾯附为了能配合上吴旗娃的分页样式, 做了细微的改动, 在此贴上全部的代码, ⽅便⼤家使⽤Default2.aspx.csusing System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data;using System.Data.SqlClient;public partial class Default2 : System.Web.UI.Page{protected SqlConnection conn; //添加数据库的操作对象protected SqlDataAdapter da;protected DataSet ds;protected SqlCommand comm;protected void Page_Load(object sender, EventArgs e){conn = new SqlConnection("Data Source=localhost;Initial Catalog=nd_data;User ID=sa;Password=aaaaaa");//取连接字符串,建⽴连接da = new SqlDataAdapter();da.SelectCommand = new SqlCommand("select name,id from xs Order by id,name DESC ", conn);ds = new DataSet();try{conn.Open();da.Fill(ds, "abs");conn.Close();}catch (SqlException e1){Response.Write(e1.ToString());}this.PageInfo.InnerHtml = PageNums.GetPageNum(ds, DataList1,5); //传⼊DataSet,DataList名称和分页⼤⼩}}Default2.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head runat="server"><title>⽆标题页</title><style type="text/css">.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}.paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}.paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}.anpager { font: 11px Arial, Helvetica, sans-serif;margin:5px 4px 0 0;padding:4px 5px 0;}.anpager .cpb {background:#1F3A87;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:0;padding:4px 5px 1px;}.anpager a {background:#FFFFFF;border:1px solid #CCCCCC;color:#1F3A87;margin: 0;padding:4px 5px 1px;text-decoration:none}.anpager a:hover{background:#1F3A87;border:1px solid #1F3A87;color:#FFFFFF;}.pages { color: #999; }.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;}</style></head><body><form id="form1" runat="server"><asp:DataList ID="DataList1" runat="server"><ItemTemplate><asp:Label ID="lbNwes" runat="server" Text='<%#Eval("id")%>'></asp:Label >&nbsp;<asp:Label ID="lbTime" runat="server" Text='<%#Eval("name")%>'></asp:Label></ItemTemplate></asp:DataList><br /><div id="PageInfo" runat="server" class="anpager"></div></form></body></html>PageNums.csusing System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;/// <summary>///PageNums 的摘要说明/// </summary>public class PageNums{/// </summary>/// <param name="ds">DataSet实例</param>/// <param name="datalistname">DataList名称</param>/// <param name="pagesize">分页⼤⼩</param>public static string GetPageNum(DataSet ds, DataList datalistname, int pagesize){PagedDataSource objPds = new PagedDataSource();objPds.DataSource = ds.Tables[0].DefaultView;objPds.AllowPaging = true;int total = ds.Tables[0].Rows.Count;objPds.PageSize = pagesize;int page;if (HttpContext.Current.Request.QueryString["page"] != null)page = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);elsepage = 1;objPds.CurrentPageIndex = page - 1;datalistname.DataSource = objPds;datalistname.DataBind();int allpage = 0;int next = 0;int pre = 0;int startcount = 0;int endcount = 0;string pagestr = "";if (page < 1) { page = 1; }//计算总页数if (pagesize != 0){allpage = (total / pagesize);allpage = ((total % pagesize) != 0 ? allpage + 1 : allpage);allpage = (allpage == 0 ? 1 : allpage);}next = page + 1;pre = page - 1;startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号//中间页终⽌序号endcount = page < 5 ? 10 : page + 5;if (startcount < 1) { startcount = 1; } //为了避免输出的时候产⽣负数,设置如果⼩于1就从序号1开始if (allpage < endcount) { endcount = allpage; } //页码+5的可能性就会产⽣最终输出序号⼤于总页码,那么就要将其控制在页码数之内pagestr = "<a >"+"共" + allpage + "页</a>&nbsp;&nbsp;&nbsp;&nbsp;";pagestr += page > 1 ? "<a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=1\">⾸页</a>&nbsp;&nbsp;<ahref=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + pre + "\">上⼀页</a>" : "<a>⾸页</a>" + "&nbsp;&nbsp;" + "<a>上⼀页</a>";//中间页处理,这个增加时间复杂度,减⼩空间复杂度for (int i = startcount; i <= endcount; i++){pagestr += page == i ? "&nbsp;&nbsp;" +"<a class=\"cpb\">"+ i + "</a>" : "&nbsp;&nbsp;<a href=\"" +HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + i + "\">" + i + "</a>";}pagestr += page != allpage ? "&nbsp;&nbsp;<a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + next + "\">下⼀页</a>&nbsp;&nbsp;<a href=\"" + HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + allpage + "\">末页</a>" :"&nbsp;&nbsp;" + "<a >下⼀页</a>" + "&nbsp;&nbsp;" + "<a >末页</a>";return pagestr;}}3个css样式写在⾥⾯了, ⽤的时候可以选选看看, 也可以⾃⼰改下⾯是效果图:。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

ASP数字分页显示代码实例
网站建设ASP初级程序员基本技能--数字分页显示<br>
数据库mdb内容:表名=Diary;字段1=DiaryID int;字段2=DiaryName nvarchar;字段3=DiaryDate datetime
<%
'On Error Resume Next
Set Conn=Server.CreateObject("ADODB.Connection")
'ConnStr="Provider=SQLOLEDB;Data Source=Chinadad;Initial Catalog=Chinadad;UID=sa;PWD=;"
'ConnStr="Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("\")&"\Diary.mdb" ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("\")&"\Diary.mdb"
''Response.Write ConnStr&"<hr>"
Conn.Open ConnStr
Set Rs=Server.CreateObject("ADODB.Recordset")
sql="Select * from Diary order by DiaryID desc"
Rs.Open sql,Conn,1,1
n=0
if not rs.eof then
PageSize=10
Rs.PageSize=PageSize
RecordCount=Rs.RecordCount
PageNo=Request("PageNo")
if PageNo="" then
PageNo=1
elseif PageNo<=0 then
PageNo=1
else
PageNo=cint(PageNo)
if PageNo>rs.PageCount then PageNo=rs.PageCount
Rs.AbsolutePage=cint(PageNo)
%>
<form method=post action="<%=Request.ServerVariables("Script_Name")%>">
<%for i=1 to PageSize
Response.Write (PageNo*PageSize+n)&"行-->"&rs("DiaryID")&"."&rs("DiaryName")&rs("DiaryDate")&"<hr>"%>
<%rs.movenext
if rs.eof then exit for
n=n+1%>
<%next%>
<%=n%>
<a href="?PageNo=1">首页</a> <%if PageNo>1 then%><a href="?PageNo=<%=PageNo-1%>">上页</a><%else%>上页<%end if%>
<%for i=0 to PageSize-1%>
<%if PageNo+1>=int(PageNo/PageSize)*PageSize then%><a href="?PageNo=<%=int(PageNo/PageSize)*PageSize+i%>">[<%=int(PageNo/PageSize)*PageSize+i%> ]</a><%end if%>
<%next%>
<%if PageNo+1<Rs.PageCount+1 then%><a href="?PageNo=<%=PageNo+1%>">下页</a><%else%>下页<%end if%> <a href="?PageNo=<%=Rs.PageCount%>">尾页</a>
<input type="text" name="pageno" value=""><input type="submit" name="submit" value="转到页面"> </form>
<%end if
if Err.Number<>0 then
Response.Write "数据库连接失败:"&Err.Description else
Response.Write "数据库连接成功:"&ConnStr
end if
%>。

相关文档
最新文档