读书人

一个难题asp判断语句不执行怎么处理

发布时间: 2012-03-07 09:13:51 作者: rapoo

一个难题,asp判断语句不执行怎么办?
<%
set rs=Server.CreateObject( "ADODB.Recordset ")
sql= "select daoshi_yiji from [daima] where daoshi_yiji is not null order by id asc "
rs.open sql,conn,1,1
for x=1 to rs.recordcount
daoshi_yiji_edit = daoshi_yiji_edit & " <option value= "&rs( "daoshi_yiji ")& " <% if ds_yjxk = " & rs( "daoshi_yiji ") & " then response.write 'selected ' %\> " & rs( "daoshi_yiji ") & " </option> "
rs.movenext
next
rs.close
application( "daoshi_yiji_edit ") = daoshi_yiji_edit '一级学科
%>
上面生成了application( "daoshi_xueli_edit ") ,只是生成了一个select表单的选项信息,但特别之处是其中又包含了一个asp的判断语句。

然后在edit页面调用这个application( "daoshi_xueli_edit "),方法如下:

<%
sql= "select * from [daoshiok] where id= "&dbid
rs.open sql,conn,1,1
ds_yjxk = rs( "ds_yjxk ")%>
<td colspan= "2 ">
<select size= "1 " name= "ds_yjxk " style= "width:100%; ">
<option value= " " > 请选择 </option>
<%=application( "daoshi_yiji_edit ")%>
</select>

为什么可以生成select列表,但是其中的asp判断语句不执行呢??

[解决办法]
自己的写法错误~!

for x=1 to rs.recordcount
daoshi_yiji_edit = daoshi_yiji_edit & " <option value= "&rs( "daoshi_yiji ")
if ds_yjxk = rs( "daoshi_yiji ") then
daoshi_yiji_edit = daoshi_yiji_edit & " selected "
end if
daoshi_yiji_edit = daoshi_yiji_edit & "> " & rs( "daoshi_yiji ") & " </option> "
rs.movenext
[解决办法]
daoshi_yiji_edit = daoshi_yiji_edit & " <option value= "&rs( "daoshi_yiji ")
if ds_yjxk = " & rs( "daoshi_yiji ") & " then
daoshi_yiji_edit=daoshi_yiji_edit+“selected”
end if
daoshi_yiji_edit=daoshi_yiji_edit+ rs( "daoshi_yiji ") & " </option> "
[解决办法]
daoshi_yiji_edit = daoshi_yiji_edit & " <option value= "&rs( "daoshi_yiji ")& " <% if ds_yjxk = " & rs( "daoshi_yiji ") & " then response.write 'selected ' %\> " & rs( "daoshi_yiji ") & " </option> "



if ds_yjxk =rs( "daoshi_yiji ") then
daoshi_yiji_edit = daoshi_yiji_edit& " <option selected value= "&rs( "daoshi_yiji ")& "> "&rs( "daoshi_yiji ") & " </option> "
else
daoshi_yiji_edit = daoshi_yiji_edit& " <option value= "&rs( "daoshi_yiji ")& "> "&rs( "daoshi_yiji ") & " </option> "
end if
[解决办法]


<%
set rs=Server.CreateObject( "ADODB.Recordset ")
sql= "select daoshi_yiji from [daima] where daoshi_yiji is not null order by id asc "
rs.open sql,conn,1,1
for x=1 to rs.recordcount
daoshi_yiji_edit = daoshi_yiji_edit & " <option value= ' "&rs( "daoshi_yiji ")& " ' "
if trim(ds_yjxk) = trim(rs( "daoshi_yiji ")) then
daoshi_yiji_edit = daoshi_yiji_edit & " 'selected '> "& rs( "daoshi_yiji ") & " </option> "
else
daoshi_yiji_edit = daoshi_yiji_edit & "> "& rs( "daoshi_yiji ") & " </option> "
end if
rs.movenext
next
rs.close
application( "daoshi_yiji_edit ") = daoshi_yiji_edit '一级学科
%>
问题:
1.
<%
………………

<%if 判断 then response.write 'selected ' /%>
………………
%>
不可以这样写
2.value= "&rs( "daoshi_yiji ")& ",value后面的值要用引号引起来,不然值为空的时候,就会把后面的代码当做值.
3.
" <option value= "&rs( "daoshi_yiji ")& " <% if ds_yjxk = " & rs( "daoshi_yiji ") & " then response.write 'selected ' %\> " & rs( "daoshi_yiji ") & " </option> "
其中 <option 没有结束符号> .
4.
<% if ds_yjxk = " & rs( "daoshi_yiji ") & " then response.write 'selected ' %\>
两个数值比较的时候,类型要一致.

其他的还没有仔细看,快迟到了,去上班了.

读书人网 >ASP

热点推荐