主题:急死了,那位大侠帮忙啊!我找出原因了,查询表单的输入框和结果在同一个页面内,翻页时输入框置空,从而
贴出了整段代码,很容易看的,网上摘的比较经典的
这个问题的关键在于查询表单和结果在同一个页面内,这样翻页时,文本框跟着刷新,从而关键字跟着置空
我编写了一个简单的设备浏览查询程序,进入页面后会分页显示所有设备,
如果在搜索框内填入关键字搜索后,如果得到的记录少于每页显示的个数18个,程序是没有问题的,
如果大于18个,只要点击下一页,则显示的记录立即变为所有记录的第二页
有网友说,用表单传递参数,我加了一句,
response.write "<form method=Post action="&filename&"?keyword="&request("keytxt")&">"
<table width="754" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="754" cellspacing="0" cellpadding="0" height="34" bgcolor="#FFCC33">
<tr>
<td width="25%" height="33">
<div align="center"><font color="#330099" size="2">设备登记</font></div>
</td>
<td width="25%" height="33">
<div align="center"><font color="#330099" size="2"><a href="xiu_index.asp" target="_self">设备修理</a></font></div>
</td>
<td width="25%" height="33">
<div align="center"><font color="#330099" size="2"><a href="jie_index.asp">设备借用</a></font></div>
</td>
<td width="25%" height="33">
<div align="center"><font color="#330099" size="2">设备转移</font></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<tr>
<td valign="top" bgcolor="#FFFFFF">
<form name="test" method="POST" action="deng_index.asp">
<p align="center"><font color="#FF0000"> 按</font>
<select size="1" name="sss">
<option value="设备名称">设备名称</option>
...............
</select>
条件 <font color="#FF0000">输入查询的字符串</font>:
[b] <input name="keytxt" type="text" id[/b]="keytxt" style="font-family: 宋体; font-size: 9pt; color: #000064" onFocus="this.value=''" size="20">
<input type="submit" value="查询" name="submit">
<input type="reset" value="全部重写" name="reset">
</p>
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db/system.asp") '## MS Access 2000 using virtual path
set my_Conn = Server.CreateObject("ADODB.Connection")
my_Conn.open strConnString
Set my_rs= Server.CreateObject("ADODB.Recordset")
%>
<%dim sss,keyword
keyword=Trim(Request("keytxt"))
if trim(request.form("sss"))<>"" then
select case request.form("sss")
case "设备名称"
strSql ="select * from jhtdata where (设备名称 like '%"&keyword&"%') and (部门='"&myUpart&"') order by id Desc"
end select
else
strSql ="select * from jhtdata where 部门='"&myUpart&"' order by id Desc"
end if
my_rs.open strSql,my_Conn,1,1
if my_rs.eof and my_rs.bof then
response.write "<p align='center'> 还 没 有 任 何 设 备 </p>"%>
<table width="754" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#CCCCFF"><img border="0" src="images_oishbgl/Form.gif" align="absmiddle" width="14" height="11">
<%=myUpart%>设备登记表 </td>
<td bgcolor="#CCCCFF"><img border="0" src="images_oishbgl/write.gif" width="16" height="16">
<%if myUrule="b" then%>
<a href="#" onClick="MM_openBrWindow('sendinf.asp','','scrollbars=yes,width=800,height=570')">
<%end if%>
登记设备</a> </td>
</tr>
</table>
<%else
totalPut=my_rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showpage totalput,MaxPerPage,"deng_index.asp"
showContent
showpage totalput,MaxPerPage,"deng_index.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
my_rs.move (currentPage-1)*MaxPerPage
showpage totalput,MaxPerPage,"deng_index.asp"
showContent
showpage totalput,MaxPerPage,"deng_index.asp"
else
currentPage=1
showpage totalput,MaxPerPage,"deng_index.asp"
showContent
showpage totalput,MaxPerPage,"deng_index.asp"
end if
end if
my_rs.close
end if
set my_rs=nothing
my_conn.close
set my_conn=nothing%>
<%
sub showContent
dim i
i=0
%>
</form>
<table border="0" width="754" bgcolor="#8080C0" align="center">
<tr>
<td width="100%" bgcolor="#CCCCFF" height="23">
<table width="336" border="0" cellspacing="0" cellpadding="0" height="20">
<tr>
<td><img border="0" src="images_oishbgl/Form.gif" align="absmiddle" width="14" height="11">
<%=myUpart%>设备登记表 </td>
<td><img border="0" src="images_oishbgl/write.gif" width="16" height="16">
<%if myUrule="b" then%>
<a href="#" onClick="MM_openBrWindow('sendinf.asp','','scrollbars=yes,width=800,height=570')">
<%end if%>
登记设备</a> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="754" border="1" style='border-collapse: collapse;table-layout:fixed;' x:str>
<tr align="center">
<td width="72" nowrap >设备名称</td>
<td width="87" >设备编号</td>
<td width="102" >规格型号</td>
<td width="93" >生产厂商</td>
<td width="75" >管理部门</td>
<td width="59" >运行状况</td>
<td width="73" >设备负责人</td>
<td width="61" >是否借出</td>
<td colspan="2" > 管理栏 </td>
</tr>
<%do while not my_rs.eof %>
<tr align="center">
<td width="72" ><a href="#" onClick="MM_openBrWindow('view_inf.asp?view_id=<%=my_rs("id")%>','','scrollbars=yes,width=660,height=550')"><%=my_rs("设备名称")%></a></td>
<td width="87" ><%=my_rs("设备编号")%></td>
<td width="102" ><%=my_rs("设备规格型号")%></td>
<td width="93" ><%=my_rs("生产厂商")%></td>
<td width="75" nowrap ><%=my_rs("部门")%></td>
<td width="59" ><%=my_rs("运行状况")%></td>
<td width="73" ><%=my_rs("设备负责人")%></td>
<td width="61" >
<%if my_rs("已借出")=false then%>
否
<%else%>
是
<%end if%>
</td>
<td width="38" >
<%if my_rs("已借出")=false then%>
<%if myUrule="b" then%>
<a href="#" onclick="MM_goToURL('parent','del_from_db.asp?delid=<%=my_rs("id")%>&delbz=My_public');return document.MM_returnValue">
<%end if%> <%end if%>
<img border="0" src="images_oishbgl/icon_delete.gif" alt="删除此条信息!" align="absmiddle" width="15" height="15">
</a>
<td width="30" >
<%if myUrule="b" then%>
<a href="#" onClick="MM_openBrWindow('edit_inf.asp?edit_id=<%=my_rs("id")%>','','scrollbars=yes,width=780,height=570')">
<%end if%>
<img border="0" src="images_oishbgl/0037.gif" width="20" height="18" alt="编辑此记录">
</a> </td>
</tr>
<%
i=i+1
if i>=MaxPerPage then exit do
my_rs.movenext
loop
%>
</table>
</table>
<%
end sub
function showpage(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
[b]关键语句[/b]
response.write "<p align='center'>&amp;nbsp;"
if CurrentPage<2 then
response.write "<font color='#000080'><a href="&amp;filename&amp;"?page=1&amp;keyword="&amp;keyword&amp;">首页</a> 上一页</font>&amp;nbsp;"
else
response.write "<a href="&amp;filename&amp;"?page=1&amp;keyword="&amp;keyword&amp;">首页</a>&amp;nbsp;"
response.write "<a href="&amp;filename&amp;"?page="&amp;CurrentPage-1&amp;"&amp;keyword="&amp;keyword&amp;">上一页</a>&amp;nbsp;"
end if
if n-currentpage<1 then
response.write "<font color='#000080'>下一页 尾页</font>"
else
response.write "<a href="&amp;filename&amp;"?page="&amp;(CurrentPage+1)&amp;"&amp;keyword="&amp;keyword&amp;">"
response.write "下一页</a> <a href="&amp;filename&amp;"?page="&amp;n&amp;"&amp;keyword="&amp;keyword&amp;">尾页</a>"
end if[b]关键语句[/b]
response.write "<font color='#000080'>&amp;amp;amp;amp;nbsp;页次:</font><strong><font color=red>"&amp;amp;amp;amp;CurrentPage&amp;amp;amp;amp;"</font><font color='#000080'>/"&amp;amp;amp;amp;n&amp;amp;amp;amp;"</strong>页</font> "
response.write "<font color='#000080'>&amp;amp;amp;amp;nbsp;共<b>"&amp;amp;amp;amp;totalnumber&amp;amp;amp;amp;"</b>个记录 <b>"&amp;amp;amp;amp;maxperpage&amp;amp;amp;amp;"</b>个记录/页</font> "
response.write "<font color='#000080'>转到:</font><input type='text' name='page' size=4 maxlength=4 class=smallInput value="&amp;amp;amp;amp;Currentpage&amp;amp;amp;amp;">&amp;amp;amp;amp;nbsp;"
response.write "<input class=buttonface type='submit' value='Go' name='cndok' >&amp;amp;amp;amp;nbsp;&amp;amp;amp;amp;nbsp;"
end function
%>