Monday, 15 September 2014

asp.net - How do I print a formview page? -



asp.net - How do I print a formview page? -

i'm trying create routine print pages formview table. have routine printing gridview, same? can modified work formview changing gridview1 formview1? work when formview in readonly mode. vb language preference. help appreciated newbie.

protected sub print_click(sender object, e system.eventargs) handles button1.click gridview1.allowpaging = false gridview1.databind() gridview1.useaccessibleheader = true gridview1.headerrow.tablesection = tablerowsection.tableheader gridview1.attributes("style") = "border-collapse:separate" each row gridviewrow in gridview1.rows if row.rowindex mod 30 = 0 andalso row.rowindex <> 0 row.attributes("style") = "page-break-after:always;" end if next dim sw new stringwriter() dim hw new htmltextwriter(sw) gridview1.rendercontrol(hw) dim gridhtml string = sw.tostring().replace("""", "'").replace(system.environment.newline, "") dim sb new stringbuilder() sb.append("<script type = 'text/javascript'>") sb.append("window.onload = new function(){") sb.append("var printwin = window.open('', '', 'left=0") sb.append(",top=0,width=1000,height=600,status=0');") sb.append("printwin.document.write(""") dim style string = "<style type = 'text/css'>thead {display:table-header-group;} tfoot{display:table-footer-group;}</style>" sb.append(style & gridhtml) sb.append(""");") sb.append("printwin.document.close();") sb.append("printwin.focus();") sb.append("printwin.print();") sb.append("printwin.close();") sb.append("};") sb.append("</script>") clientscript.registerstartupscript(me.[gettype](), "gridprint", sb.tostring()) gridview1.allowpaging = true gridview1.databind() end sub

i trimmed/changed above next below "system.web.httpexception: command 'formview1' of type 'formview' must placed within form tag runat=server." error message , totally lost how prepare it. error comes line "formview1.rendercontrol(hw)"

protected sub button5_click(sender object, e system.eventargs) handles button5.click formview1.allowpaging = false formview1.databind() formview1.headerrow.tablesection = tablerowsection.tableheader formview1.attributes("style") = "border-collapse:separate" dim sw new stringwriter() dim hw new htmltextwriter(sw) formview1.rendercontrol(hw) dim gridhtml string = sw.tostring().replace("""", "'").replace(system.environment.newline, "") dim sb new stringbuilder() sb.append("<script type = 'text/javascript'>") sb.append("window.onload = new function(){") sb.append("var printwin = window.open('', '', 'left=0") sb.append(",top=0,width=1000,height=600,status=0');") sb.append("printwin.document.write(""") dim style string = "<style type = 'text/css'>thead {display:table-header-group;} tfoot{display:table-footer-group;}</style>" sb.append(style & gridhtml) sb.append(""");") sb.append("printwin.document.close();") sb.append("printwin.focus();") sb.append("printwin.print();") sb.append("printwin.close();") sb.append("};") sb.append("</script>") clientscript.registerstartupscript(me.[gettype](), "gridprint", sb.tostring()) formview1.allowpaging = true formview1.databind() end sub

it turns out needed 2 things. 1. needed add together routine vb code behind:

public overrides sub verifyrenderinginserverform(control control) ' confirms htmlform command rendered specified asp.net server command @ run time. end sub i needed add together next aspx code header:

enableeventvalidation = "false"

all working , have added similar "export excel" function.

asp.net vb.net

No comments:

Post a Comment