|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
[ASP]关于修改数据后返回页码问题
大概意思是这样的,就是假若我现在在第10页修改,修改成功后自动返回的也还在当前页,我把当前页输出都正常,可以显示在第几页,就是返回的不行,总是返回第一页?或是出现错误提示?为何,请帮帮忙,下面是代码:
[code]
<!--#include file="../zj64_publicfile/Const.asp" -->
<!--#include file="../zj64_publicfile/DB_Conn.asp" -->
<!--#include file="../zj64_publicfile/Function.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
dim pmcount,pageno
s_keyword = trim(request("keyword"))
s_cataid=trim(request("cataid"))
pageno=trim(request("pageno"))
if pageno="" then pageno=1
response.write pageno
pmcount=news_back_count
dim rs,sql
set rs=server.createobject("adodb.recordset")
Function DelNews(idstr)
sqld = "select * from zj64_company where floor_id="&idstr
set rsd=Server.CreateObject("ADODB.RecordSet")
rsd.Open sqld,conn,1,3
if not rsd.EOF then
strpath=rsd("floor_photo")
Filename = Server.MapPath(strpath)
Set fs = CreateObject("Scripting.FileSystemObject")
if strpath<>"" then
If fs.FileExists(Filename) Then
fs.DeleteFile(Filename)
end if
end if
sql="delete from zj64_company where floor_id="&idstr
conn.execute sql
end if
End Function
if request("action")="Del" then
Dim strIdList,arrIdList,iId,i
strIdList = Trim(Request("news"))
if stridlist="" then
response.write"<script>alert('没有选中任何数据!');history.go(-1);</script>"
response.end
else
If Not IsEmpty(strIdList) Then
arrIdList = Split(strIdList,",")
For i=0 To UBound(arrIdList)
iId = clng(arrIdList(i))
Call DelNews(iId)
Next%>
<script>alert('删除成功!');location.href='zj64_company_list.asp';</script>
<%End If
end if
end if
%>
<%
if request("action")="Audit" then
dim idlist1,arrlist1,i1,i2
idlist1 = trim(request("news"))
if idlist1="" then
response.write"<script>alert('没有选中任何数据!');history.go(-1);</script>"
response.end
else
if not isempty(idlist1) then
arrlist1 = split(idlist1,",")
for i2=0 to ubound(arrlist1)
i1 = clng(arrlist1(i2))
call shenghe(i1)
next
response.write"<script>alert('推荐成功!');location.href='zj64_company_list.asp';</script>"
end if
end if
end if
if request("action")="uAudit" then
dim idlist8,arrlist8,i8,i9
idlist8 = trim(request("news"))
if idlist8="" then
response.write"<script>alert('没有选中任何数据!');history.go(-1);</script>"
response.end
else
if not isempty(idlist8) then
arrlist8 = split(idlist8,",")
for i9=0 to ubound(arrlist8)
i8 = clng(arrlist8(i9))
call ushenghe(i8)
next
end if
response.write pageno
response.write"<script>alert('取消推荐操作成功!');location.href='zj64_company_list.asp?pageno="&pageno&"&cataid="&s_cataid&"&txtitle="&txtitle&"';</script>"
end if
end if
Function shenghe(id_sh)
conn.execute("update zj64_company set floor_flage=1 where floor_id="&id_sh)
end Function
Function ushenghe(id_sh)
conn.execute("update zj64_company set floor_flage=0 where floor_id="&id_sh)
end Function
%>
<html>
<head>
<title>企业管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=javascript>
function check(Str)
{
document.delnews.action="?action=" + Str;
document.delnews.submit();
}
</script>
<script language="JavaScript">
<!--
function cdel(){
if (confirm("你真的要删除这些企业吗?不可恢复!")){
document.delnews.submit();;
}
}
function view(newsfile) {
var gt = unescape('%3e');
var popup = null;
var over = "Launch Pop-up Navigator";
popup = window.open('', 'popupnav', 'width=480,height=500,left=200,top=200,,resizable=no,scrollbars=no');
if (popup != null) {
if (popup.opener == null) {
popup.opener = self;
}
popup.location.href = newsfile;
}
}
function SelectCheckBox()
{
for(i=0;i<document.delnews.elements.length;i++)
{
if(document.all("selectCheck").checked == true)
{
document.delnews.elements[i].checked = true;
}
else
{
document.delnews.elements[i].checked = false;
}
}
}
//-->
</script>
<link href="../zj64_publicfile/text.css" rel="stylesheet" type="text/css">
</head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table width="750" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#efefef" id="Table2">
<tr>
<form action=? method=post name="toGetNewsList" id="Form1">
<td width="873" height="30" align=left> 搜索:
<input name="keyword" type=text value="<%=s_keyword%>">
<select name="cataid" size="1" style="height:18" onChange="javascript:document.toGetNewsList.submit();" id="Select1">
<option value="">选择类别直接进入</option>
<%set rsc=server.CreateObject("adodb.recordset")
sqlc="Select * from zj64_company_lb"
rsc.Open sqlc,conn,1,3
do while not rsc.EOF%>
<option value="<%=rsc("id")%>" <%if rsc("id")="&s_cataid&" then%>selected<%end if%>><%=rsc("title")%></option>
<%rsc.movenext
loop%>
</select>
<input type="submit" name="Submit" value=" 搜 索 "> </td>
<td width="124" align=right>
<input name=reloadPage type=button value=" 刷 新 " id="reloadPage" onClick="javascript:window.location.reload();"> </td>
</form>
</tr>
</table>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="1" bordercolorlight="#efefef" bordercolordark="#FFFFFF" bgcolor="#6a6a6a">
<tr align="center" bgcolor="#efefef">
<td height="28" colspan="6"> 企业信息列表 <a href="zj64_company_Add.asp">添加企业信息</a></td>
</tr><tr align="center" bgcolor="#efefef">
<td width="57" height="28">
选 定 </td>
<td width="137" height="28">
类 别 </td>
<td width="88" height="28">
序 号 </td>
<td width="436" height="28">
公司名称 </td>
<td width="207" height="28">
发布时间 </td>
<td width="58" height="28">
修改 </td>
</tr>
<form name="delnews" action="?pageno=<%=request("pageno")%>" method=post>
<%
if s_cataid="" then
if s_keyword<>"" then
sql ="select * from zj64_company where floor_gsmc like '%"&s_keyword&"%' order by floor_id desc"
else
sql="select * from zj64_company order by floor_id desc"
end if
else
if s_keyword<>"" then
sql ="select * from zj64_company where floor_lb='"&s_cataid&"' and floor_gsmc like '%"&s_keyword&"%' order by floor_id desc"
else
sql="select * from zj64_company where floor_lb='"&s_cataid&"' order by floor_id desc"
end if
end if
rs.open sql,conn,1,1
rcount=rs.recordcount
if pmcount="" or isempty(pmcount) or pmcount<1 then
pmcount=19
end if
rs.pagesize=pmcount '设置每页数
mpage=rs.pagecount '得到总页数
pageno=clng(request("pageno"))
if isempty(pageno) or cint(pageno)<1 or cint(pageno)>mpage then
pageno=1
end if
if rs.bof and rs.eof then
response.write "<tr><td colspan='6'>没有企业</td></tr>"
else
rs.absolutepage=pageno
loopno=pmcount
i=1
do while not rs.eof and loopno>0
%>
<tr align="center" bgcolor="#FFFFFF">
<td width="57" height="26">
<input type='checkbox' name='news' value='<%=Trim(rs("floor_id"))%>' style="border:0px"> </td>
<td width="137" height="26">
<%
sqlh = "select * from zj64_company_lb where id="&rs("floor_lb")
set rsh=Server.CreateObject("ADODB.RecordSet")
rsh.Open sqlh,conn,1,1
if not rsh.EOF then
response.write rsh("title")
else
response.write ("该类别不存在!")
end if
rsh.close
set rsh=nothing
%> </td>
<td width="88" height="26"><%=rs("floor_id")%></td>
<td width="436" height="26" align="left"> <%=rs("floor_gsmc")%><%if rs("floor_flage")=1 then %>
[<font color=ff0000>已推荐</font>]
<%end if%></td>
<td width="207" height="26">
<%=rs("floor_time")%> </td>
<td width="58" height="26">
<a href="zj64_company_modify.asp?floor_id=<%=rs("floor_id")%>&page=<%=pageno%>">修改</a></td>
</tr>
<%
rs.movenext
loopno=loopno-1
i=i+1
loop
end if
rs.close
set rs=Nothing
%>
</form>
<tr align="center" bgcolor="#FFFFFF">
<form name="pageform" method=get action="?pageno=<%=request("pageno")%>">
<td height="26" colspan="6"><input type='checkbox' name='selectCheck' id=selectCheck onclick="SelectCheckBox()" style="border:0px">全部选中 <input name="delbtn" value="删除企业" type="button" onclick="check('Del')"> <input name="delbtn" value="推荐企业" type="button" onclick="check('Audit')"> <input name="delbtn" value="取消推荐" type="button" onclick="check('uAudit')"> 跳到第<input type=text size=3 name="pageno" value="<%=pageno%>">页
<%if cint(pageno)>1 then%>
[<a href='?cataid=<%=s_cataid%>&keyword=<%=s_keyword%>&pageno=<%=pageno-1%>' class="tt4">上一页</a>]
<%end if
if cint(pageno)<cint(mpage) then%>
[<a href='?cataid=<%=s_cataid%>&keyword=<%=s_keyword%>&pageno=<%=pageno+1%>' class="tt4">下一页</a>]
<%end if%>
共<%=cstr(pageno)&"/"&cstr(mpage)&"页 "&cstr(rcount)%>家企业
<input name="pageno" type="hidden" id="pageno" value="<%=request("pageno")%>"></td>
</form>
</tr>
</table>
</body>
</html>[/code] |
忘了说了,推荐企业和取消推荐都是在一个页面完成的,就是取消推荐后再次返回的时候,不能返回到当前页的问题, |
就是不知道错在哪了. |
代码太长,不想看了
思路:
如果是form提交数据,<form>中增加<input type="hidden" value="<%=pageno%>" name="pageno">
如果是querystring传递,在连接中增加<a href="xxx.asp?pageno=<%=pageno%>&action=edit">编辑</a>
数据显示和处理在一个页面这样很不好,安全性太差,特别是对于FORM刷新都可能出错,比较好的办法是分成两个页面:
举例:
manage.asp '数据、结果显示页面
<form action="updateinfo.asp" method="post">
........
[color=Red]<input name="mode" value="edit" type="hidden">[/color] '保存编辑结果
<input type="submit" value="确定"
</form>
......
<form action="updateinfo.asp?[color=Red]mode=del[/color]" method="post"> '执行删除操作
.......
</form>
<a href="updateinfo.asp?id=<%=id%>&[color=Red]mode=setstatus[/color]">设置状态</a>
.......
上面举了3种典型例子传递参数mode到updateinfo.asp,至于操作完成手返回原页面在下面的程序中实现:
updateinfo.asp 文件内容: (集中操作程序)
[color=blue]url = Request.ServerVariables ("http_referer")[/color]
[color=red]select case request("mode")[/color]
[color=red]case "edit"[/color]
...
执行记录修改程序
...
[color=red]case "del"[/color]
...
执行删除程序
...
[color=red]case "setstatus"[/color]
...
执行设置状态程序
...
[color=red]case else[/color]
...
出错处理(没有操作类型参数)
...
[color=red]end select[/color]
[color=blue]response.redirect url[/color]
注意上面红色代码部分是控制操作类型,蓝色代码部分就是返回先前的页面代码 |
你在修改的时候隐藏一个input,值记录页数,执行程序后返回该页 |
非常感谢:[b][color=red]woochysean[/color][/b]
你的思路太清晰,太好了,问题解决,我终于知道我错在哪里,非常感谢. |
我一般是这样处理,使用中觉得很方便的,看对你有没有用
1、首先编写这样三个函数
[code]'== 取得当前页面的URL地址
Function CurrentURL()
Dim tmpstr, URL
If Request.ServerVariables("HTTPS") = "ON" Then URL = "https://" Else URL = "http://"
URL = URL & Request.ServerVariables("HTTP_HOST")
tmpstr = Request.ServerVariables("SERVER_PORT")
If tmpstr <> 80 Then URL = URL & ":" & tmpstr
URL = URL & Request.ServerVariables("PATH_INFO")
tmpstr = Trim(Request.ServerVariables("QUERY_STRING"))
If tmpstr <> Empty Then URL = URL & "?" & tmpstr
CurrentURL = URL
End Function
'== 将当前页面的URL地址写入Cookie变量
Sub WriteCurrentURL()
Response.Cookies("URL") = CurrentURL
End Sub
'== 读取Cookie变量中的页面URL信息
Function ReadCurrentURL()
ReadCurrentURL = Request.Cookies("URL")
End Function[/code]
2、然后在头一个页面一开始调用WriteCurrentURL过程,把当前页面的地址存入Cookie中去。在编辑页面编辑完成后用response.redirect ReadCurrentURL语句转回去。
这样不用传页码参数,而且如果列表页面是条件查询得来的,那传的参数就更多了,呵呵。这样做什么都不用管,参数都带着呢! |
|