[求助]出错啦,下标越界,请帮我看看!

dd5555 2003-08-18 07:01:31
叶面上
<%do while not rs.eof%>
<input type="hidden" name="ID" value="<%=ID%>">
<input type="hidden" name="price" value="<%=price%>">
<%
rs.movenext
loop
%>
提交时就会有多个price 和 ID
这样接受语句
<%
If Not IsEmpty(Request.Form) Then
If Not Request.Form("price") = "" Then
ID=Trim(Request.Form("ID"))
price=Trim(Request.Form("price"))
arrayID = split(ID,",")
arrayprice = split(price,",")
for i=lbound(arrayID) to ubound(arrayID)
strSql = "UPDATE [TBL_EXCHANGE_RATE] SET [price]='" & arrayprice(i) & "', [TimeStamp]='" & now() & "' WHERE ID = '" & arrayID(i) & "'"
conn.execute strSql
next
End If
End If
%>
上面一切正常,我现在要再多加一个字段[是否显示]做成打勾和不打勾,意思是不打勾就不显示这行数据。
<input type="hidden" name="ID" value="<%=ID%>">
<input type="hidden" name="price" value="<%=price%>">
<input name="xianshi" type="checkbox" id="xianshi" value="True" checked>
问题是,我加上这段后在作相应修改,在提交数据时全选就正常,如果有几个没打勾就没有数据,会出错提示:i下标越界
...全文
48 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxrl 2003-08-20
  • 打赏
  • 举报
回复
给你一段代码,或许有用,对你。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>usermanager1</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="inc/body.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function cform(){
if(!confirm("您确认删除选中的用户!"))
return false;
}
function shenhe_user()
{
if (!confirm("您确认让该用户通过审核!"))
return false;
}
</script>
<body>
<!--#include file="INC/CONFIG.ASP" -->
<%
select case request("forbid")
case "禁用"
call forbidcontrol()
case "删除"
call delete_for_selected_checkbox()
case else
end select
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><a href="REGISTER.ASP" target="main"><img src="IMAGES/user_1.gif" border="0"></a>
</td>
</tr>
<tr>
<td> 
<%
strsql="select u.*,d.ftype,q.quarters_type from tuser u,tdepart d,quarters q where (u.id_depart=d.id )and (u.id_quarters=q.id) order by u.id desc"
set rs= Server.CreateObject("adodb.recordset")
rs.open strsql,conn,1,3
%>
<!--#include file="turnpage.asp" -->
<%
if rs.eof then
Response.Write"<font color=red>还没有添加任何用户</font>"
else
dim rowcount
rowcount=5
call turnpage(rs,rowcount)
%>
<form method="post" >
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="12%" align="center">姓名</td>
<td width="21%" align="center">注册用户</td>
<td width="14%" align="center">所属部门</td>
<td width="16%" align="center">所在岗位</td>
<td width="15%" align="center">审核</td>
<td width="6%" align="center">修改</td>
<td width="6%" align="center"><input type="submit" value="禁用" name="forbid"></td>
<td width="10%" align="center"><input name="forbid" type="submit" id="forbid" style="border:1pt solid #636563;font-size:9pt; LINE-HEIGHT: normal;HEIGHT: 18px;" onclick="return cform();" value="删除"></td>
</tr>
<%
do while not rs.eof and rowcount>0
%>
<tr>
<td align="center"><%= rs("realname") %></td>
<td align="center"><%= rs("loginname") %></td>
<td align="center"><%= rs("ftype") %></td>
<td align="center"><%= rs("quarters_type") %></td>
<td align="center"><% if rs("fshenhe")=true then %>已审核<% else %><a href="shenhe.asp?id=<%= rs("id") %>" onclick="return shenhe_user();">未审核</a><% end if %></td>
<td align="center"><a href="#" onclick="MM_openBrWindow('modregister.ASP?id=<%= cstr(rs("id")) %>','','width=400,height=300')">修改</a></td>
<td align=center><input type="checkbox" name="forbidid" value="<%=cstr(rs("id"))%>"<%=checked(rs("forbid"),"yes")%>>
<input type="hidden" name="allid" value="<%=rs("id")%>">
<td align="center"><input name="seledel" type="checkbox" id="seledel" value="<%=cstr(rs("id")) %>"></td>
</tr>
<%
rowcount=rowcount-1
rs.movenext
loop
%>
</table>
</form>
<% end if %>
</td>
</tr>
</table>
<p> </p></body>
</html>
<%
sub forbidcontrol()
count=0
count1=0
allid=""
condition=""
notcondition=""
for each id in request("allid")
count1=count1+1
allid=allid & id
if count1<request("allid").count then
allid=allid+","'///////////////////////得到相关id集用“id1,id2,id3”的形式
end if
next
for each idno in request("forbidid")
count=count+1
condition=condition+"id=" & idno'得出sql语句的条件,形式如下:id=1 or id=2 or id=3,id是从页面中的CHECKBOX是否已经被选中的情况
'如果选中,那么就有一个选中的集合,idno是集合中的最小元素。
notcondition=notcondition+"id<>" & idno
if count<request("forbidid").count then
condition=condition+" or "'如果不是最后一个,那么就加上“ or ”
notcondition=notcondition+" and "'如果不是最后一个,那么就加上“ and ”
end if
next
'///////////下面应该懂了吧!
if condition<>"" then
sql = "update tuser set forbid='yes' where " & condition
conn.Execute sql
end if
if notcondition<>"" then
'这个SQL语句,你可能不太清楚,翻译如下:
'sql = "update tuser set forbid='no' where id in (1,2,3,4,5,6,7,8,9,10) and id<>11 and id<>12 and id<>13"
sql = "update tuser set forbid='no' where id in (" & allid & ") and " & notcondition
else
sql = "update tuser set forbid='no' where id in (" & allid & ")"
end if
conn.Execute sql
end sub
sub delete_for_selected_checkbox()
dim idlist
if not isempty(request("seledel")) then
idlist=request("seledel")
if instr(idlist,",")>0 then
dim idarr
idArr=split(idlist)
dim id
for i = 0 to ubound(idarr)
id=clng(idarr(i))
call deleteannounce(id)
next
else
call deleteannounce(clng(idlist))
end if
end if
end sub
sub deleteannounce(id)
dim rs,sql
' set rs=server.createobject("adodb.recordset")
sql="delete from tuser where id="&cstr(id)
conn.execute sql
End sub
%>
dd5555 2003-08-20
  • 打赏
  • 举报
回复
我觉得这样做不怎么合理,没有打勾的如果以前已经是打了勾,不能自动更新为不显示吧?我看只能更新打勾的为显示。有没有好的解决方案?
anita2li 2003-08-19
  • 打赏
  • 举报
回复
没打勾的是传不过去的﹐你只要知道打勾的﹐不打勾的还不知道吗﹖
接收的时候不要固定数组的长度﹐用name=Split(Request(“name”),”,”)就可以了﹐然后用For i=0 to Ubound(name)遍例就可以了
dd5555 2003-08-19
  • 打赏
  • 举报
回复
这样怎么传我打勾或不打勾的值?
dd5555 2003-08-18
  • 打赏
  • 举报
回复
3243rf34t
ccmoon 2003-08-18
  • 打赏
  • 举报
回复
你可以这样做
显示的checkbox不管
然后增加一个hidden字段,进行传值
叶面上
<%do while not rs.eof%>
<input type="hidden" name="ID" value="<%=ID%>">
<input type="hidden" name="price" value="<%=price%>">
<input type="hidden" name="pageview" value="<%=pageview%>">
<input name="xianshi" type="checkbox" id="xianshi" value="True" checked disabled>
<%
rs.movenext
loop
%>
这样你就拥有一样多的数组,就不会越界
注意checkbox值传打钩得值上去
ccmoon 2003-08-18
  • 打赏
  • 举报
回复
因为没打钩的值不会传上去,所以没打钩字段没有那么多值
zorou_fatal 2003-08-18
  • 打赏
  • 举报
回复
<input name="xianshi" type="checkbox" id="xianshi" value="True" checked>
你是怎么读取这些数据的呢?

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧