欢迎光临
我们一直在努力

ASP.net的ACCESS数据分页方案-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月
中国it动力,最新最全的it技术教程
ASP.net的ACCESS数据分页方案-.NET教程,Asp.Net开发 最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线api文档 ASP.net的ACCESS数据分页方案-.NET教程,Asp.Net开发
ASP.net的ACCESS数据分页方案-.NET教程,Asp.Net开发 首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 未整理篇 | 技术讨论

asp js php工程 asp.net 网站建设 uml j2eesun .net vc vb vfp 网络维护 数据库 db2 sql2000 oracle mysql
服务器 win2000 office c dreamweaver fireworks flash photoshop 上网宝典 coreldraw 协议大全 网络安全 微软认证
  当前位置: > 程序开发 > web开发 > asp > 综合文章
asp.net的access数据分页方案
作者:未知 时间:2005-06-23 12:12 出处:blog 责编:chinaitpower
              摘要:暂无

常用asp.net分页为 datagrid 控件 和 ado分页

本分页为缓存唯一标识字段 只选出分页后的记录

对大量数据库分页提高了效率

netpage.vb

imports system.web
imports system.data
imports system.data.oledb

namespace rynetpage
    public class netpage
        inherits system.web.ui.page
        private conn as oledbconnection
        private ds as dataset
        private dt as datatable
        private sqlstr, scriptname as string
        private getpage, pagecount, listcount as integer
        private orderstr, tablestr, indexstr, columnstr, jscriptstr as string
        private pagesizenum as integer
        private pageindex as string
        public sub new()
            scriptname = “rynetpage”
            pagesizenum = 10
        end sub
        public writeonly property connstr()
            set(byval value)
                try
                    conn = new oledbconnection(value)
                    conn.open()
                catch ex as exception
                    echo(“.new” & ex.message.tostring)
                end try
            end set
        end property
        public writeonly property jscript() as string
            set(byval value as string)
                jscriptstr = value
            end set
        end property
        public writeonly property pagesize() as string
            set(byval value as string)
                pagesizenum = convert.toint32(value)
            end set
        end property
        public writeonly property order() as string
            set(byval value as string)
                if appcache(“order”) <> value then
                    orderstr = “order ” & value
                    appcache(“order”) = orderstr
                    writeindex()
                end if
            end set
        end property
        public writeonly property table() as string
            set(byval value as string)
                tablestr = “[” & value & “]”
            end set
        end property
        public writeonly property index() as string
            set(byval value as string)
                indexstr = value
            end set
        end property
        public writeonly property column() as string
            set(byval value as string)
                columnstr = value
            end set
        end property
        public readonly property recordscount() as integer
            get
                try
                    writeindex()
                    dt = appcache(“index”)
                    return dt.rows.count
                catch ex as exception
                    echo(“.recordscount ” & ex.message.tostring)
                end try
            end get
        end property
        public function showrecords() as datatable
            try
                sqlstr = “select ” & columnstr & ” from ” & tablestr & pagewhere()
                writeindex()
                dim adapt as oledbdataadapter
                adapt = new oledbdataadapter(sqlstr, conn)
                ds = new dataset
                ds.clear()
                adapt.fill(ds)
                return ds.tables(0)
            catch ex as exception
                echo(“.showrecords ” & ex.message.tostring)
            end try
        end function
        public function showpage(optional byval getstr as string = “”) as string
            dim temp as string
            temp = “<script language=””jscript”” src=””” & jscriptstr & “””></script>” & chr(13)
            temp += “<script language=””jscript””>pages(” & getpage + 1 & “,” & pagecount & “,” & listcount & “,” & getstr & “page)</script>”
            return temp
        end function
        public sub clear()
            appcache(“index”) = nothing
        end sub
        private function pagewhere() as string
            try
                dim epage as integer
                dim i as integer
                dt = appcache(“index”)
                getpage = convert.toint32(httpcontext.current.request.querystring(“page”))
                listcount = recordscount()
                pagecount = cint(fix(listcount / pagesizenum) + 1)
                if listcount mod pagesizenum = 0 then
                    pagecount = pagecount – 1
                end if
                if getpage = 0 or pagecount < getpage then
                    getpage = 1
                end if
                getpage = getpage – 1
                if listcount < pagesizenum or getpage = pagecount then
                    epage = listcount – 1
                else
                    epage = (getpage * pagesizenum + pagesizenum) – 1
                end if
                for i = (getpage * pagesizenum) to epage
                    pageindex += dt.rows(i)(0) & “,”
                    if i = listcount – 1 then exit for
                next
                pageindex = left(pageindex, len(pageindex) – 1)
                return ” where ” & indexstr & ” in(” & pageindex & “)”
            catch ex as exception
                echo(“.pagewhere ” & ex.message.tostring)
            end try
        end function
        private sub writeindex()
            try
                if (appcache(“index”) is nothing) then
                    dim adapt as oledbdataadapter
                    adapt = new oledbdataadapter(“select ” & indexstr & ” from ” & tablestr & orderstr, conn)
                    ds = new dataset
                    ds.clear()
                    adapt.fill(ds)
                    appcache(“index”) = ds.tables(0)
                end if
            catch ex as exception
                echo(“.writeindex ” & ex.message.tostring)
            end try
        end sub
        private property appcache(byval setname as string)
            get
                return httpcontext.current.application.get(scriptname & “_” & tablestr & “_” & setname)
            end get
            set(byval value)
                httpcontext.current.application.lock()
                httpcontext.current.application.set(scriptname & “_” & tablestr & “_” & setname, value)
                httpcontext.current.application.unlock()
            end set
        end property
        private sub echo(byval value as string)
            dispose()
            httpcontext.current.response.write(value)
            httpcontext.current.response.end()
        end sub
        protected overrides sub finalize()
            mybase.finalize()
            dispose()
        end sub
        public overrides sub dispose()
            if not (conn is nothing) then
                conn.dispose()
            end if
        end sub
    end class
end namespace

pages.js

function pages(requestpage,maxpage,recordcount,pagename){
var p,ii;
if((requestpage-1)%10==0)
 p=(requestpage-1)/10;
else
 p=parseint((requestpage-1)/10);
 document.write(<font class=”smalltxt”>);
 document.write(&nbsp;+recordcount+&nbsp;);
 document.write(&nbsp;+requestpage+/+maxpage+&nbsp;&nbsp;pages&nbsp;);
if(requestpage==1)
 document.write(&lt;);
else
 document.write(<a href=?+pagename+=1 title=首页>&lt;</a>);
 if(p*10>0)
 {
  document.write( <a href=?+pagename+=+p*10+ title=上十页>..</a>);
 }
 for(ii=p*10+1;ii<=p*10+10;ii++)
 {
  if(ii==requestpage)
  {
   document.write ( <u><font color=”#cc0033″>+ii+</font></u> );
  }
  else
  {
   document.write ( <a href=?+pagename+=+ii+>+ii+</a> );
  }
 if(ii==maxpage)
  break;
 }

if(ii<maxpage)
{
 document.write(<a href=?+pagename+=+ii+ title=下十页>..</a> );
 if(requestpage==maxpage)
  document.write(&gt;);
 else
  document.write(<a href=?+pagename+=+maxpage+ title=尾页>&gt;</a>);
}
 document.write(</font>&nbsp;<input class=”sbut” type=”text” size=”1″ name=”page” value=”+requestpage+” class=”pageinput”>&nbsp;<input class=”sbut” type=”button” value=”go”  onclick=”window.location=\?+pagename+=\+page.value”>);
}

调用示范

dim net = new netpage

        connstr = “provider=microsoft.jet.oledb.4.0;data source=” & server.mappath(“database/rybbs.mdb”)
        dim i as integer
        net.jscript = server.mappath(“jscript/pages.js”) js分页函数地址
        net.connstr = connstr 连接数据库
        net.pagesize = 20 每页显示数
        net.table = “test” 表名
        net.index = “id” 唯一标识字段名
        net.column = “id,title,content” 要显示的字段名
        net.order = “by id desc” 排序
        dim rs as datatable
        rs = net.showrecords 调出分页后的记录
        response.write(“<table>”)
        for i = 0 to rs.rows.count – 1
            response.write(“<tr>” & chr(13))
            response.write(“<td>” & rs.rows(i)(0) & “</td><td>” & rs.rows(i)(1) & “</td><td>” & rs.rows(i)(2) & “</td>” & chr(13))
            response.write(“</tr>” & chr(13))
        next
        response.write(“<table>” & chr(13))
        response.write(net.showpage(“id=20&”) & “<br>”) id=20&为一同传递的其它分页参数
        response.write(formatnumber(timer – run, 6))

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.net的ACCESS数据分页方案-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章