asp.netsql-server-2008gridviewlinkbutton

Get Image from database by clicking on link button in gridview in asp .Net


I have LinkButton in grid view

<asp:TemplateField HeaderText="Images">
       <ItemTemplate>
          <asp:LinkButton ID="lnkDrvImgLic" CommandArgument='<%# Eval("intVou") %>' CommandName="viewLicImg" runat="server">Licence Image</asp:LinkButton>
       </ItemTemplate>
    </asp:TemplateField>

<%#Eval("intVou") %> is Primary key and it should show the image from database based on primary key. Does it requires any parameter for server path? It would be fine if I can open image in new tab.


Solution

  • Or you can instead use the Hyperlink control like this:

    <asp:HyperLink  NavigateUrl='<%# String.Concat("~/",Eval("ImagePathField")) %>' Target="_blank" runat="server" >L</asp:HyperLink>
    

    Notice that you must use "~/" to get the relative path for the image. Also you need to add Target"_blank" to open the image in new tab.

    Hope this helps.