asp分页基础类XDownPage2.0只支持oracle,而 2.10已经能够支持sqlserver了。本例将演示XDownPage2.10对于sqlserver数据库的分页方法。 1 , 分页程序代码 请详见另一篇文章 :http://blog.csdn.net/precipitant/archive/2006/11/15/1386541.aspx 2, conn.asp
asp分页基础类xdownpage2.0只支持oracle,而 2.10已经能够支持sqlserver了。本例将演示xdownpage2.10对于sqlserver数据库的分页方法。
1 , 分页程序代码
请详见另一篇文章:http://blog.csdn.net/precipitant/archive/2006/11/15/1386541.aspx
2 , conn.asp(数据库连接相关的程序)
'==================================================
' 数据库访问
'==================================================
'建立数据库连接
dim conn '数据库连接对象
set conn=server.createobject("ADODB.CONNECTION")
sub openConn
connstr="Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=it;User Id=it_manage;Password=it_manage;"
conn.open connstr
end sub
'清除数据库连接
sub CloseConn
conn.Close()
set conn=nothing
end sub
'关闭打开的记录集
sub CloseRS(byref recordset)
recordset.close()
set recordset=nothing
end sub
'获得当前虚拟目录的名字
function getRoot()
url=Request.ServerVariables("URL")
url=right(url,len(url)-1)
getRoot= mid(url,1,instr(url,"/")-1)
end function
'---------------- 数据库排序 start ---------------------------
sImageDir = "/" & getRoot() & "/images/" '图片路径
upOrderFlag = "" &sImageDir & "sort_asc.gif'>" '升序排列显示图标
downOrderFlag = "" &sImageDir & "sort_desc.gif'>" '降序排列显示图标
'获得当前连接的排序方向
function getOrderDir(fn,ofn,oDir)
dim tDir
tDir="desc"
if(lcase(fn)=lcase(ofn)) then
if(lcase(oDir)="asc") then
tDir="desc"
else
tDir="asc"
end if
end if
getOrderDir=tDir
end function
'书写排序指示图标
function writeOrderDir(fn,ofn,oDir)
dim tDir
if(lcase(fn)=lcase(ofn)) then
if(lcase(oDir)="asc") then
tDir=UpOrderFlag
else
tDir=downOrderFlag
end if
end if
writeOrderDir=tDir
end function
'添加排序列头
sub WriteOrderHeader(pHeaderTitle,pOrderField,tOrderField,tOrderDir)
Response.Write "" & pOrderField & "','" & getOrderDir(pOrderField,tOrderField,tOrderDir) & "')"" class='noticetitle' style="max-width:90%">" & pHeaderTitle & " " & writeOrderDir(pOrderField,tOrderField,tOrderDir) & ""
end sub
'---------------- 数据库排序 end ---------------------------
3 , main.asp(主程序)
...
'故障类别管理
'writer:northsnow
'create date :051211
%>
script language="javascript">...
//执行查询前将查询条件写到隐藏表单
function query()
...{
var oFormHidden=document.frmHidden;
if(!oFormHidden) return false;
oFormHidden.currentpage.value="";
oFormHidden.flag.value="query";
oFormHidden.err_type_name.value=frmList.err_type_name.value;
oFormHidden.err_type_code.value=frmList.err_type_code.value;
oFormHidden.submit();
}
//重置查询条件
function myreset()
...{
frmList.err_type_name.value="";
frmList.err_type_code.value="";
}
//执行动态排序
function gotoOrder(uOrderField,uOrderDir)
...{
frmHidden.currentpage.value="1";
frmHidden.flag.value="query";
frmHidden.orderField.value=uOrderField;
frmHidden.orderDir.value=uOrderDir;
frmHidden.submit();
}
}
script>
... 'on error resume next
'获取参数
dim err_type_name,err_type_code
dim currentpage,flag,pagesize,rsTotalCount,orderDir,orderField
currentpage=trim(request.form("currentpage"))
p_p=trim(request("p_p"))
flag=trim(request("flag"))
pagesize=trim(request("pagesize"))
rsTotalCount=trim(request("rsTotalCount"))
orderDir=trim(Request("orderdir"))
orderField=trim(Request("orderfield"))
err_type_code=trim(request("err_type_code"))
err_type_name=trim(request("err_type_name"))
%>
span >>> 故障类别管理span>
p align=center>span >
fieldset style="width:100%;padding:'2px 2px'" align="center" >
legend align=right style="border:0px">
a href="#" onclick="javascript:query()" tabindex="1">查询a>|
a href="#" onClick="javascript:myreset()" >重置a>
legend>
table width="100%" align="center" ID="Table1">
tr >form name="frmList" action="#" method="post" ID="Form1">
td valign="middle" align="center" >
table width="100%" border="0" cellspacing="0" cellpadding="0" ID="Table2">
tr>
td align="center" width="50%">类别代码:
input name="err_type_code" type="text" maxlength="4" value="" ID="Text1">td>
td align="center" width="50%">类别名称:
input name="err_type_name" type="text" value="" size="22" ID="Text2">td>
tr>
table>
td>
tr>form>
table>
fieldset>span>
table width=100% align=center border="0" cellpadding="0" cellspacing="0" ID="Table3">
form name="manForm" ID="Form2">tr>td align=center valign=top>
table border="0" width="100%" cellspacing="0" cellpadding="0" ID="Table4">
...
'定义记录集对象
set rs=server.CreateObject("adodb.recordset")
rs.CursorLocation=3 '定义记录集的属性
if pagesize="" then pagesize=15 '定义默认页大小
'//形成查询条件串
strOption="where 1=1"
if err_type_code"" then
strOption=strOption & " and err_type_code='"&err_type_code&"'"
end if
if err_type_name"" then
strOption=strOption & " and err_type_name like '%"&err_type_name&"%'"
end if
'形成排序串
strOrder=""
if orderField"" then
strOrder=" order by " & orderField
if orderDir"" then strOrder=strOrder & " " & orderDir
end if
if strOrder="" then strOrder=" order by err_type_code asc"
'连接数据库
Call OpenConn()
Set mypage=new xdownpage '创建分页类对象
mypage.getconn=