Assemble link only when there is data

Asked

Viewed 74 times

0

I have a webforms application. In this application I have this line in my Asp.net.

<strong><a href="/UpLoads/<%# Eval("DsPathDocumento")%>" class="linkUpload"><%# Eval("NmTipoDocumento")%></a></strong>

Well, what I want is that this link only mounts when there is document. I went through and is giving error that it is only possible inside a Databound.

if(!String.IsNullOrEmpty(Eval("DsPathDocumento ").ToString())) { %>
                <<strong><a href="/UpLoads/<%# Eval("DsPathDocumento")%>" class="linkUpload"><%# Eval("NmTipoDocumento")%></a></strong>
                <% } %

>

How do I fix this? That is the mistake:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
  • What is the property on your Dataset that says the registry has or has no documents? The folder is Dspathdocument, but there must be a "Temdocumento" property in your Dataset, so you can tell if the link should appear or not.

  • The Dspathdocumento field itself is the field I want to test. If it brings something is that there is document, if it comes null or empty has no document. It is by this field that I want to create the link.

1 answer

2

If you only want the link to be viewed or not, then use the Style Tag together with the Display property.

<strong>
    <a class="linkUpload" <%# Eval("SEQ_CHA") != null && !String.IsNullOrEmpty(Eval("SEQ_CHA").ToString()) ? String.Concat("href='/UpLoads/", Eval("SEQ_CHA"), "'") : "href='#' style='cursor: default; color:#000000;'" %>>
        <%# Eval("NmTipoDocumento")%>
    </a>
</strong>
  • I changed the answer to stay as specified.

  • Yes, they will have the tag like HREF, but will not link anywhere. If you want to delete the HREF tag and leave only the written text, then this is something else. The ternary is correct, I tested it.

  • I changed again.

  • Dude, we’re almost there and I really appreciate it. I just need the next one and I don’t know how to get it out. Continue the underline and when I click, it goes back to a certain page. I would like to click nothing happened and as I do to remove the underlining. Now I think the underscore has to do with the upload class, I’ll try it here.

  • You no longer have the link when it contains nothing, the underscore is probably in your class.

  • But when I click on it, it opens me another window with this: about:Blank

  • You’re doing something wrong. I’m sure the code works because I’m testing it here. the "#" does not redirect to anywhere, it serves with anchor.

  • I removed href='#' and now redirects me to a blank page only. Before it went back to the calling page and after I removed it redirects me to the about:Lank and opens in another window.

  • I removed the class="linkUpload" and now what does not have doc attached does nothing and what has doc, the link is created, but both situations, creates the underline. I can’t remove the underline.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.