ASP 中如何根据数据库中取出的值来判定 checkbox或radio 的状态是否为选中

示例:

apply_type,apply_reason:为数据库中取出来的值  注意:必须做去空格处理

apply_reason="," & Replace(Trim(dbRs("apply_reason"))," ","") & ","

 apply_type="," & Trim(dbRs("apply_type")) & ","

单选框:

 

 

<%
                strSql="SELECT Dict_type,Dict_name FROM dbo.TS_Dictionary WHERE Catalog_id='3056' ORDER BY Dict_type"
                dbRs.open strSql,dbConn,1,1
                IF dbRs.RecordCount>0 THEN
                dbRs.MoveFirst
                DO WHILE NOT dbRs.EOF 
                Dict_type=Trim(dbRs("Dict_type")) 
                Dict_name=Trim(dbRs("Dict_name")) 
                    %>
                    <input type="radio" id="type_<%=Dict_type%>" name="apply_type" value="<%=Dict_type%>"  <%if instr(apply_type,("," & Dict_type &","))>0 then response.write "checked" end if%> /><label
                        for="type_<%=Dict_type%>"><%=Dict_name%></label>&nbsp;&nbsp;&nbsp;
                    <%
                dbRs.MoveNext
                LOOP
                END IF
                dbRs.close
%>

                 

多选框: 

  <%
                strSql= " SELECT Dict_type,Dict_name FROM dbo.TS_Dictionary WHERE Catalog_id='3066' ORDER BY CONVERT(INT,Dict_type) "
                dbRs.open strSql,dbConn, 1, 1
                 IF dbRs.RecordCount> 0  THEN
                dbRs.MoveFirst
                 DO  WHILE  NOT dbRs.EOF 
                Dict_type= Trim(dbRs( " Dict_type ")) 
                Dict_name= Trim(dbRs( " Dict_name ")) 
                    IF Dict_name= " 其他 " THEN 
                   
                     %>
                    
                    < input  type ="checkbox"  id ="reason_other"  name ="apply_reason"  <%if instr(apply_reason,("," & Dict_type &",")) >0 then response.write "checked" end if%>  value=" <%=Dict_type %>" /> < label
                        
for ="reason_other" > <%=Dict_name %> </ label >
                     < input  type ="text"  name ="apply_other"  style ="border-style: none none solid none;
                        border-bottom-width: 1px; border-bottom-color: #000000"
  />
                     <%  ELSE %>
                     < input  type ="checkbox"  id ="reason_<%=Dict_type%>"  name ="apply_reason"  value ="<%=Dict_type%>"  <%if instr(apply_reason,("," & Dict_type &",")) >0 then response.write "checked" end if%> /> < label
                        
for ="reason_<%=Dict_type%>" > <%=Dict_name %> </ label > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                     <% END  IF 

                dbRs.MoveNext
                 LOOP
                 END  IF
                dbRs.close
                     %>

关键语句是:<%if instr(apply_reason,("," & Dict_type &","))>0 then response.write "checked" end if%> 

将input的值也做"," & Dict_type &","处理,是为了防止 当值为1时, apply_reason中有11或10等包含1这个数字的值从而出现错误的判断。

转载于:https://www.cnblogs.com/gssajl/archive/2012/10/09/2716285.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值