我现在回到经典ASP并想要隐藏具有空值的超链接。此超链接将ID转移到详细信息视图。如果详细信息(字段:突出显示)为空,则隐藏超链接。如果存在突出显示,我只希望显示超链接。
我有以下代码,但我不知道如何整合它。我刚刚在ASP.NET中完成了这个,但是我对如何在Classic ASP中获得它感到困惑。任何建议将不胜感激:
if objRS.recordcount = 0 then
response.write "<p>Check back soon.</p>"
else
do while not objRS.eof
' Display Table Data
response.write "<td><a href='highlights.asp?ID=" & objRS.fields("ID") & "'>Read Highlights</a></td>"
' Loop it
objRS.movenext
loop
response.write "</table>"
end if
以前在.NET中,我正在做以下事情:
<asp:PlaceHolder ID="PlaceHolder2" runat="server" Visible='<%# IIf((Eval("Highlights")).ToString().Length > 0, "true", "false") %>'>
<h3>Read Highlights</h3>
<asp:Label ID="highlights" runat="server" Text='<%# Bind("Highlights") %>'></asp:Label>
</asp:PlaceHolder>
不确定我是在右边还是在错误的轨道上,这不起作用......说对象是必需的......
If objRS.fields("Highlights") Is Not Null Then
response.write "<td><a href='highlights.asp?ID=" & objRS.fields("ID") & "'>Read Highlights</a></td>"
End if
尝试这个:
If objRS.fields("Highlights") = NULL Then
response.write "<td> </td>"
Else
response.write "<td><a href='highlights.asp?ID=" & objRS.fields("ID") & "'>Read Highlights</a></td>"
End if
在这里得到: 注意:代码没有粘贴格式,看起来很混乱
If Not (IsNull(objRS("Highlights"))) Then response.write "<td><a href='highlights.asp?ID=" & objRS.fields("ID") & "'>Read Highlights</a></td>" Else response.write "<td> </td>" End if
答案 0 :(得分:1)
VBScript中的null运算符称为Nothing
If objRS.fields("Highlights") is Nothing or Then
response.write "<td> </td>"
Else
response.write "<td><a href='highlights.asp?ID=" & objRS.fields("ID") & "'>Read Highlights</a></td>"
End if
编辑,但是如果你必须测试该字段是空还是空,我总是有这个功能:
function IsEmpty(f)
IsEmpty = IsNull(f) or trim(f) = ""
end function
所以你的代码将是:
If IsEmpty(objRS.fields("Highlights")) Then
response.write "<td> </td>"
Else
response.write "<td><a href='highlights.asp?ID=" & objRS.fields("ID") & "'>Read Highlights</a></td>"
End if
答案 1 :(得分:0)
if objRS.recordcount = 0 then
response.write "<p>Check back soon.</p>"
else
do while not objRS.eof
' Display Table Data
IF NOT ISNULL(objRS.fields("Highlights")) AND objRS.fields("Highlights") <> "" THEN
response.write "<td><a href='highlights.asp?ID=" & objRS.fields("ID") & "'>Read Highlights</a></td>"
END IF
' Loop it
objRS.movenext
loop
response.write "</table>"
end if