locked
Gridview Hyperlink RRS feed

  • Question

  • User-1162697930 posted

    Hello, I am trying to create a hyperlink column coming from database to pull multiple file extensions. Right now it is only doing .jpg but I like to also be able to pull .pdf as well. Here is my code but I don't know how to add .pdf to this code.

    <ItemTemplate>
    <asp:HyperLink ID="HyperLinkParts" runat="server" Text= '<%# Eval("PartNumber") %>'
    NavigateUrl= '<%#Eval("PartNumber", "~/Hardware/{0}.jpg") %>'
    </ItemTemplate>

    Tuesday, February 13, 2018 5:44 PM

All replies

  • User409696431 posted

    Please clarify what problem you are having.   Is this link supposed to do both .jpg and .pdf?  If so, obviously, hardcoding .jpg into the link won't work.  If it is supposed to do both, you need {0} to contain the full filename, with extension, not add the extension in code.

    Tuesday, February 13, 2018 9:10 PM
  • User3690988 posted

    Would something like this work for you?

    <ItemTemplate>
     <asp:HyperLink ID="HyperLinkParts" runat="server" Text= '<%# Eval("PartNumber") %>'
      NavigateUrl= '<%#Eval("PartNumber", "~/Hardware/{0}.jpg") %>' />
     <asp:HyperLink ID="hlPDF" runat="server" Text="pdf"
      NavigateUrl= '<%#Eval("PartNumber", "~/Hardware/{0}.pdf") %>' />
    </ItemTemplate>

    Wednesday, February 14, 2018 12:55 PM
  • User-1162697930 posted

    Thanks for your reply, but if I don't add the extension it will not pull anything. The code I have now only looks at the file name without the extension, that is why I am adding the extension.

    Wednesday, February 14, 2018 1:48 PM
  • User-1162697930 posted

    Thanks for your reply paindassp, I had already tried this but with 'Eval("PartNumber")' for text. Either my way or your way, it gives me two sets of text in that same column. The first set are .jpg and the second sets are .pdf.

    Wednesday, February 14, 2018 1:51 PM
  • User3690988 posted

    If you do not want 2 links to 2 different file types, what exactly are you looking for?

    Wednesday, February 14, 2018 2:17 PM
  • User409696431 posted

    It helps if you are clear in your requirements.  As it is, we are guessing.   Is your question simply, "how to make two columns instead of one"?  Put each link inside its own <ItemTemplate>...</ItemTemplate> rather than having both in one <ItemTemplate>.

    Wednesday, February 14, 2018 8:03 PM
  • User-1716253493 posted

    if you have extention column, you can do this in VB

    NavigateUrl= '<%#Eval("PartNumber", "~/Hardware/{0}.") & Eval("Extension") %>'

    Thursday, February 15, 2018 10:44 AM