Click here to Skip to main content
15,913,685 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Open PDF from Gridview Link Pin
Abhijit Jana25-Jul-09 10:29
professionalAbhijit Jana25-Jul-09 10:29 
GeneralRe: Open PDF from Gridview Link Pin
PDTUM25-Jul-09 12:03
PDTUM25-Jul-09 12:03 
GeneralRe: Open PDF from Gridview Link Pin
Abhijit Jana25-Jul-09 12:25
professionalAbhijit Jana25-Jul-09 12:25 
GeneralRe: Open PDF from Gridview Link Pin
PDTUM25-Jul-09 12:43
PDTUM25-Jul-09 12:43 
GeneralRe: Open PDF from Gridview Link Pin
Abhijit Jana25-Jul-09 20:50
professionalAbhijit Jana25-Jul-09 20:50 
GeneralRe: Open PDF from Gridview Link Pin
PDTUM26-Jul-09 4:13
PDTUM26-Jul-09 4:13 
GeneralRe: Open PDF from Gridview Link Pin
Abhijit Jana26-Jul-09 7:22
professionalAbhijit Jana26-Jul-09 7:22 
AnswerRe: Open PDF from Gridview Link Pin
PDTUM26-Jul-09 12:47
PDTUM26-Jul-09 12:47 
Abhijit,

Thank you for your help.....and all others that responded to my request. Your help is greatly appreciated. I have come up with a solution for this dilemma, as submitted to me by PeteNet at the ASP.Net forum. It is nice and tight, easy to understand, and works perfectly. I wish to post it here for the benefit of all others that might be interested.

use a LinkButton within a TemplateField in your GridView:

<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandArgument = '<%#Eval("<filename>")%>' OnClick="OpenPDF">OpenPDF</asp:LinkButton>
</ItemTemplate>

in the codebehind write the event handler OpenPDF:

protected void OpenPDF(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)sender;
if (lnk != null)
{
Response.AddHeader("content-disposition", "attachment; filename=" + lnk.CommandArgument + ".pdf");
Response.WriteFile(Server.MapPath("~/PDFs/" + lnk.CommandArgument.ToString() + ".pdf" ));
Response.End();
}
}

commandArgument will hold the filename (from the database, for the current row in the grid)...depending on whether you have the extension stored along with the filename you may want to append or remove ".pdf" in the code (lnk.CommandArgument + ".pdf")

replace <filename> with the actual value of your database column name that holds the file name

if you use VB.NET you can convert over here: http://www.developerfusion.com/tools/convert/csharp-to-vb/

Good Luck and Best Regards to All, Pat
GeneralRe: Open PDF from Gridview Link Pin
Abhijit Jana26-Jul-09 13:20
professionalAbhijit Jana26-Jul-09 13:20 
Questioni facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Ramesh Reddy1111125-Jul-09 8:01
Ramesh Reddy1111125-Jul-09 8:01 
AnswerRe: i facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Abhijit Jana25-Jul-09 8:45
professionalAbhijit Jana25-Jul-09 8:45 
AnswerRe: i facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Manas Bhardwaj25-Jul-09 11:04
professionalManas Bhardwaj25-Jul-09 11:04 
GeneralRe: i facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Ramesh Reddy1111125-Jul-09 15:59
Ramesh Reddy1111125-Jul-09 15:59 
GeneralRe: i facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Abhijit Jana25-Jul-09 21:21
professionalAbhijit Jana25-Jul-09 21:21 
GeneralRe: i facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Ramesh Reddy1111125-Jul-09 21:43
Ramesh Reddy1111125-Jul-09 21:43 
GeneralRe: i facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Manas Bhardwaj25-Jul-09 22:11
professionalManas Bhardwaj25-Jul-09 22:11 
GeneralRe: i facing problom to run asp.net3.5 block book sample projects. the error message is Pin
Abhijit Jana25-Jul-09 22:24
professionalAbhijit Jana25-Jul-09 22:24 
QuestionCommandName Pin
arkiboys25-Jul-09 5:36
arkiboys25-Jul-09 5:36 
AnswerRe: CommandName Pin
Abhijit Jana25-Jul-09 5:49
professionalAbhijit Jana25-Jul-09 5:49 
GeneralRe: CommandName Pin
arkiboys25-Jul-09 5:52
arkiboys25-Jul-09 5:52 
GeneralRe: CommandName Pin
Mike Ellison25-Jul-09 8:34
Mike Ellison25-Jul-09 8:34 
GeneralRe: CommandName Pin
arkiboys25-Jul-09 9:27
arkiboys25-Jul-09 9:27 
GeneralRe: CommandName Pin
Abhijit Jana25-Jul-09 9:33
professionalAbhijit Jana25-Jul-09 9:33 
GeneralRe: CommandName Pin
arkiboys25-Jul-09 9:34
arkiboys25-Jul-09 9:34 
AnswerRe: CommandName Pin
Abhijit Jana25-Jul-09 9:37
professionalAbhijit Jana25-Jul-09 9:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.