Tuesday 15 March 2011

c# - Hyperlink field is empty while exporting gridview to PDF -



c# - Hyperlink field is empty while exporting gridview to PDF -

i work in asp.net. have gridview, 2 of it's columns hyperlinks (the others regulardatafield). that:

<asp:templatefield headertext="costumer"> <itemtemplate> <asp:hyperlink id="hyperlink1" runat="server" navigateurl='<%# eval("customer_id", "javascript:void(window.open(&#039;custsubsdetailspage.aspx?customer_id={0}&#039;,&#039;&#039;,&#039; width=500, height=500, top=100, left=100&#039;))") %>' text='<%# eval("customer_id") %>'></asp:hyperlink> </itemtemplate> </asp:templatefield>

in cs code utilize databind, , export pdf. works perfectrly except 2 columns empty.

edit requested here code pdf file:

protected void btnexportpdf_click(object sender, eventargs e) { gridview.allowpaging = false; gridview.databind(); itextsharp.text.pdf.pdfptable table = new itextsharp.text.pdf.pdfptable(gridview.columns.count); table.widthpercentage = 90; table.rundirection = pdfwriter.run_direction_rtl; (int = 0; < gridview.columns.count; i++) { string celltext = headers[i]; basefont bf = basefont.createfont("c:\\windows\\fonts\\arial.ttf", basefont.identity_h, basefont.embedded); itextsharp.text.font font = new itextsharp.text.font(bf, 6, itextsharp.text.font.normal, basecolor.black); itextsharp.text.pdf.pdfpcell cell = new itextsharp.text.pdf.pdfpcell(new phrase(8, celltext, font)); table.addcell(cell); } (int = 0; < gridview.rows.count; i++) { if (gridview.rows[i].rowtype == datacontrolrowtype.datarow) { (int j = 0; j < gridview.columns.count; j++) { string celltext = server.htmldecode(gridview.rows[i].cells[j].text); basefont bf = basefont.createfont("c:\\windows\\fonts\\arial.ttf", basefont.identity_h, basefont.embedded); itextsharp.text.font font = new itextsharp.text.font(bf, 6, itextsharp.text.font.normal, basecolor.black); itextsharp.text.pdf.pdfpcell cell = new itextsharp.text.pdf.pdfpcell(new phrase(8, celltext, font)); table.addcell(cell); } } } document pdfdoc = new document(pagesize.a4_landscape, 10f, 10f, 10f, 0f); pdfwriter.getinstance(pdfdoc, response.outputstream); pdfdoc.open(); pdfdoc.add(table); pdfdoc.close(); response.contenttype = "application/pdf"; response.addheader("content-disposition", "attachment;" + "filename=dlf_log_report_" + datetime.now + ".pdf"); response.cache.setcacheability(httpcacheability.nocache); response.write(pdfdoc); response.end(); }

can please help me figure out problem? in advance.

property text cannot used itemtemplate. should utilize next code such columns:

string celltext = server.htmldecode((gridview.rows[i].cells[j].findcontrol("hyperlinkid") hyperlink).navigateurl);

c# asp.net pdf gridview hyperlink

No comments:

Post a Comment