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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with printing large datagrid

Status
Not open for further replies.

ryDen

Programmer
Jun 6, 2002
71
AP
Hi,

I'm trying to print the contents of a datagrid. I want the format of the datagrid to remain, but it is done by css. The following code works for a small datagrid, but not for large datagrid, i.e., the contents go into more than 1 page when print manually:

Response.Clear()
Response.Buffer = True
Response.ContentType = "text/HTML"
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Charset = ""
EnableViewState = False

Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Dim scr As New StringBuilder
scr.Append("TITLE>View List</TITLE>")
scr.Append("<LINK href='./Styles.css' type='text/css' rel='stylesheet'>")
scr.Append("<script>function window.onafterprint(){history.back(1);}</script" & ">")
oHtmlTextWriter.Write(scr.ToString)

Me.lblCriteria.RenderControl(oHtmlTextWriter)
Me.dagExport.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.Write("<script>window.print();</script" & ">")
Response.End()

It seems that when I remove the following lines:
scr.Append("TITLE>View List</TITLE>")
scr.Append("<LINK href='./Styles.css' type='text/css' rel='stylesheet'>")
the code works, but my formatting is lost.

Can someone advise me on this problem?
Thanks in advance.

Russ
 
Well, after experimenting, it seems that having the css and using javascript "print" function screws up when printing more than one page. Would be nice if someone could explain why though...

Thanks anyway.
 
You can control your printing by linking two different style sheets depending on MEDIA

<link rel="stylesheet" type="text/css" media="screen" href="css\page.css">
<link rel="stylesheet" type="text/css" media="print" href="css\print.css">

that might help you out, just copy your Styles.css to a Print.css and link away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top