请教-关于单选按钮组的问题-大家帮忙看看是什么问题

cawebs 2010-10-31 03:16:53
大家帮忙这段代码哪里错了!
<!--#include virtual="/easp/conn.asp" -->
<body>
<form id="form2" name="form2" method="post" action="单选按钮组.asp">
<p>
<label>
<input type="radio" name="an" value="1" id="an_0" />
1</label>
<br />
<label>
<input type="radio" name="an" value="2" id="an_1" />
2</label>
<br />
<label>
<input type="radio" name="an" value="3" id="an_2" />
3</label>
<br />
<br />
</p>
<input type="hidden" value="act" name="act" />
<input type="submit" name="button" id="button" value="提交" />
</form>

<%
if request.Form("act")="act" then
dim rs,sql,an,val
an=request.Form("an")
response.Write an
set rs = Server.CreateObject("ADODB.RecordSet")
sql="select * from 单选按钮 "
rs.open sql,conn,3,3
%>
<%if rs.EOF and rs.BOF then
response.write ("没数据")
else
%>
<form id="form1" name="form1" method="post" action="">
<%while not rs.eof%>

<%=rs("val")%>
<label>
<input type="radio" name="ann" value="<%=rs("val")%>" <%if rs("val")=an then%>checked="checked"<%end if%> />
<%=rs("no")%>
</label>
<br />
<%
rs.MoveNext()
wend
end if

%>
</form>

<%
rs.close
set rs=Nothing
end if
%>


(Access)数据表“单选按钮” 有 字段“val”和“no”,有3条记录,记录值分别是1、2、3
现在我想当在form2里的单选按钮组选择了1,提交到form1时,rs("val")的值等于接收到form2的值的时候,form1里的那个单选按钮就被选中,可是上面的代码没达到那个效果,把<%if rs("val")=an then%>改成<%if rs("val")=1 then%>,form1里的值等于1的就可以被选中,该怎么修改呢!
...全文
61 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cawebs 2010-10-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 theforever 的回复:]
<input type="radio" name="ann" value="<%=rs("val")%>" <%if cstring(rs("val"))=cstring(an) then%>checked="checked"<%end if%> />

做一下类型转换。
[/Quote]

我把数据类型改成了 int 就可以了,谢谢提醒,改成int没什么影响吧?
cawebs 2010-10-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 theforever 的回复:]
<input type="radio" name="ann" value="<%=rs("val")%>" <%if cstring(rs("val"))=cstring(an) then%>checked="checked"<%end if%> />

做一下类型转换。
[/Quote]

改了之后提示:
Microsoft VBScript 运行时错误 错误 '800a000d'

类型不匹配: 'cstring'

  • 打赏
  • 举报
回复
<input type="radio" name="ann" value="<%=rs("val")%>" <%if cstring(rs("val"))=cstring(an) then%>checked="checked"<%end if%> />

做一下类型转换。

28,391

社区成员

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

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