Search code examples
htmlasp.nethrefrepeater

asp.net - Create contatenated href tag in a repeater element


I have a repeater on my asp.net page, bound to a datareader in code-behind. I'd like to turn one of the repeater elements into the href of an anchor tag. The repeater element is the name of a file, and I want my user to be able to click on the tag to download the file.

This post got me pretty close; my repeater element looks like this:

<%#Eval("DocumentName")%>

And my anchor looks like this:

<a href= "docs/?<%#Eval("DocumentName")%>"><%#Eval("DocumentName")%></a>

This opens the docs subfolder in a directory listing of the entire docs folder. I want the 'Open/Save File' dialog to open when my user clicks the href, not go to a separate page that lists the files in the docs directory.


Solution

  • Instead of linking to a page that lists the files, link to the actual document. If the documents are static files in the docs folder, and DocumentName is the file name, then removing the question mark from your link should do the trick.

    <a href="docs/<%#Eval("DocumentName")%>"><%#Eval("DocumentName")%></a>
    

    Note, I also removed a space after href= in your link. Not sure if that was a typo in your question or not.