Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have a gridview in aspx page as below
ASP.NET
<asp:GridView ID="grdclnsubforselpat" runat="server" BorderColor="#B1B3B3" BorderWidth="1px"
     CellPadding="2" Width="735px" AutoGenerateColumns="False" EnableModelValidation="True">
     <columns>
         <asp:BoundField DataField="ReferenceNumber" HeaderText="Reference Number" />
         <asp:BoundField DataField="PatientName" HeaderText="Patient Name" />
         <asp:BoundField DataField="PatientDob" HeaderText="Date of Birth " />
         <asp:BoundField DataField="RequestedFrom" HeaderText="Requested From" />
         <asp:HyperLinkField DataTextField="Status" HeaderText="Status" />
         <asp:HyperLinkField DataTextField="Letter" HeaderText="Letter" />
     </columns>
I am calling a stored procedure whose result I am saving in a list and assigning as data source to this gridview for binding.
There is a Column "Letter" which is a varbinary in my database.
whenever there is no value it will display as "Letter Not Available"

Now,
I have to add this varbinary column to gridview such that when letter is available in database the column should appear as Open Letter and once we click open letter the varbinary code in the DB field should be converted to a letter and should be viewed as PDF letter otherwise display a message in the column as “Not Available Online”


I tried checking the list for not available and dynamically adding the hyperlink field but I am not sure how to display a different message in front end and on clicking open a pdf.

any help is appreciated. thank you in advacne
Posted
Updated 15-Dec-15 7:07am
v2

OnRowDatabound event of GridView, just find the control and change the Text.

You can call an ashx handler on click of that link and open a pdf with the help of response object.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Dec-15 16:11pm    
Excuse me, there is no a standard way to "open a PDF". Moreover, this is not the inquirer needs. Please see Solution 2.
—SA
Sergey, OP just wants to open a PDF file separately, but not inside the html. That why I suggested to use a handler to render that.

So when user clicks on the link, on a new tab it will load the PDF only no html. :)
Sergey Alexandrovich Kryukov 15-Dec-15 23:03pm    
Well, I'm not so sure. How would you understand "Display a PDF file in Gridview" then? Perhaps, just bad wording...
The inquirer accepted your answer, no sure if it was understood. If you are right, it's a good answer.
—SA
Yeah the title is confusing. But description pointed me in that direction. :)

Thanks Sergey. :)
Sergey Alexandrovich Kryukov 15-Dec-15 23:24pm    
I must admit I cannot fully understand it. Perhaps I have less patience for such things than you do.
Also, I got a strong impression that having any PDF content at all, in this situation, is simply insane.
Based on that, I think I have to quite contributing to this page. I'll keep my answer for a while, until the inquirer provides some feedback; if I get some evidence that my answer as off-topic, I'll remove or replace it...
—SA
You should never assume that the client's system supports PDF, which is not a part of W3 standard. It would not be a problem if PDF was requested as a separate page. Some systems have PDF support, usually in the form of some browser plug-ins. Such clients will give a choice to show it as a page or save the file. Other systems will only allow the user to save a file, which is not a problem at all; the user can always view or print it later; some systems may have no PDF support at all.

If you want to have PDF inside some HTML element, don't even try. Instead, you have to parse PDF, extract structured data the way you want and map it to HTML in one or another way. If course, the resulting HTML can be the content of your table cell (GridView is always rendered in HTML as table element).

You have to parse PDF on the server side. This is a set of references to PDF libraries you can use: http://csharp-source.net/open-source/pdf-libraries.

—SA
 
Share this answer
 
Comments
anupama962010 15-Dec-15 16:34pm    
HI, All our servers, systems have PDF support. I have added a link button in the Gridview Row command event and I am saving the varbinary value from database to astring in c# code. Now my question is when I am trying to click on the link button from front end.. the event is firing and I am able to retrieve the varbinary value from db as string. how tocopy this string to byte array char by char entirey so that I can open a window and display the pdf?
Sergey Alexandrovich Kryukov 15-Dec-15 16:43pm    
I'm talking about browsers. They don't. Anyway, this is irrelevant: none of the browsers support PDF inside an HTML element. There is no such thing. So, you got a comprehensive answer.
Are you going to accept it formally?

Your question about varbinary value looks totally unrelated to the present one. You should better ask a separate question.

—SA

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