tags:

views:

95

answers:

1

Hi there,

I would like to disable a link based on the database value (ASP page). Does anyone know how to do this? Are there any example available? Need your help. Thanks.

A: 

This is a pretty vague question but in Classic ASP you can use VBScript to test your database value and then Response.Write out either the anchor tag or just a span tag with the text:

<%
    If CBool(rs("showlink")) = True Then
      %>
        <a href="somewhere.asp">Link Text</a>
      <%
    Else
      %>
        <span>Link Text</span>
      <%
    End If
%>

This assumes that you are getting a recordset back from the database (named rs) and that it has a field on it called "showlink" that will indicate if the anchor tag should be displayed or not. Small side note: Keep in mind that showing or hiding the anchor tag is not a replacement for proper authentication/security.

Jeff Widmer
Hi there, I have tried to implement your codes. But it doesn't work. The codes as below :<% If CBool(rs.Fields.Item("StudentStatusConfirm").Value="YES") = True Then %> <a href="company_student_icon.asp"><img src="company_student.png" width="52" height="51" border="0"></a> <% Else %> <span><img src="company_student.png" width="52" height="51" border="0"></span> <% End If%> I can't figure out what's wrong with the codes. Please help. Thank you.
are you getting an error or is it only displaying the Else part of the If-Then block?
Jeff Widmer
One thing to watch out for is if the StudentStatusConfirm field is returning yes in all caps. You could do this: If CBool(UCASE(rs.Fields.Item("StudentStatusConfirm").Value)="YES") = True Then
Jeff Widmer