Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an anchor tag inside gridview to open pdf file but the link is not working its not opening file

my code is:
C#
<asp:gridview id="gvRpt" runat="server" autogeneratecolumns="false" width="99%" borderstyle="None"
           borderwidth="1px" cellpadding="2" cssclass="mGrid" allowpaging="true" pagesize="10"
           style="margin-top: 0px" onpageindexchanging="gvRpt_PageIndexChanging" onrowdatabound="gvRpt_RowDataBound">
           <columns>
               <asp:templatefield headertext="Sr. No." headerstyle-wrap="false">
                   <itemtemplate>
                       <%#Container.DataItemIndex+1 %>
                   </itemtemplate>
                   <itemstyle cssclass="GridDataC" wrap="false"></itemstyle>
               </asp:templatefield>
               <asp:boundfield datafield="BankName" headertext="Bank Name">
                   <itemstyle cssclass="GridDataL"></itemstyle>
               </asp:boundfield>
               <asp:boundfield datafield="BankCode" headertext="Bank Code">
                   <itemstyle cssclass="GridDataC"></itemstyle>
               </asp:boundfield>
               <asp:boundfield datafield="FileName" headertext="File Name">
                   <itemstyle cssclass="GridDataL"></itemstyle>
               </asp:boundfield>
               <asp:templatefield headertext="Download">
                   <itemtemplate>
                       <b><a id="lnkDownload" target="_blank" href="D:/Lubna/ReportGeneration_WinApp/ReportGeneration_WinApp/DownloadPDF/HDF/HDFReport_27Aug2014_051145.pdf" runat="server" >Download</a></b>
                   </itemtemplate>
                   <itemstyle cssclass="GridDataC" wrap="false"></itemstyle>
               </asp:templatefield>
               <asp:boundfield datafield="Statusdesc" headertext="Status" />
               <asp:boundfield datafield="CreatedDate" headertext="Created Date" dataformatstring="{0:dd-MMM-yyyy}" />
           </columns>
       </asp:gridview>


when I click on download it doesn't open file. file name and location is proper I have tested it even with simple html page with only anchor tag it is working fine in html page. is there issue with gridview ?? please help me how to open pdf file from anchor tag which is inside gridview.

Thanks in advance.
Posted
Updated 10-Sep-14 1:49am
v2
Comments
ZurdoDev 10-Sep-14 7:43am    
Your link is to the d drive which means it has to exist on the client machine as D.
Sanya.Kherani 10-Sep-14 7:56am    
yes the file is in d: on my machine, and m testing it on my machine only but its not opening file. same code I wrote in one simple html page with just <html>
<body>
download
</body>
</html>

it works there it opens pdf file in another window then why its not working in asp.net?? is it because it is placed inside grid??
ZurdoDev 10-Sep-14 8:02am    
It's just an a tag so it doesn't matter that it is in a grid.

What does happen when you click the link?

Examine the link using your browser's developer tools.
Sanya.Kherani 10-Sep-14 8:14am    
nothing happens when I click the link and I checked with developers tool the path of href which was correct because when I copied the path from there and tried to open directly from my computer then file opened which means path is correct, m really not getting what is the problem here.

1 solution

make one directory in your solution and store all needed PDF file in it.
then give just path of that directory.
hope you can get it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900