Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Gridlines do not Print after the First Page.

ASP.Net Troubleshooting

Datagrid Gridlines do not Print after the First Page.

by  Mike555  Posted    (Edited  )
When printing a webform containing a datagrid longer than one printed page, the datagrid's gridlines may only print on Page 1. This problem occurs due to an IE bug which effects borderCollapsing on client-side tables. (The datagrid is rendered as a table during run-time)

There are 2 ways (which i know of) to work around this issue.

1st Method- Simply implement Paging within your datagrid to ensure that records never print past page 1.

2nd Method- Implement the following 2 Javascript functions into the HTML view of the webform containing the datagrid...
Code:
<HTML>
<HEAD>
<SCRIPT language="Javascript">
		function clearAttrs()
		{
		document.all.DataGrid1.style.borderCollapse = "separate";
		}
		function setAttrs()
		{
		document.all.DataGrid1.style.borderCollapse = "collapse";
		}
</SCRIPT>
</HEAD>
<body onafterprint="setAttrs() onbeforeprint="clearAttrs()>
</body>
</HTML>
However, if you have a datagrid that is not visible when the page initially loads, you may need to format your Javascript a bit differently. For example, you have 2 datagrids, DataGrid1 & DataGrid2, located on a webform which are not initially visible when the page loads. You may need to format the Javascript as follows...
Code:
<HTML>
<HEAD>
<SCRIPT language="Javascript">
		function clearAttrs()
		{
		if (document.all.DataGrid1 != null)
			document.all.DataGrid1.style.borderCollapse = "separate";
		else if (document.all.DataGrid2 != null)
			document.all.DataGrid2.style.borderCollapse = "separate";
		}
		function setAttrs()
		{
		if (document.all.DataGrid1 != null)
			document.all.DataGrid1.style.borderCollapse = "collapse";
		else if (document.all.DataGrid2 != null)
			document.all.DataGrid2.style.borderCollapse = "collapse";
		}
</SCRIPT>
</HEAD>
<body onafterprint="setAttrs() onbeforeprint="clearAttrs()>
</body>
</HTML>

HTH,
Mike
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top