Can somebody help me with printing a webgirid.
I want to open a pop up(acts as print preview) window when i click on the print icon, the pop up should display the grid in printable state (without any styles just plain text inside table).
1. Add the grid into a div control:
-------------------------------------------------------------------------------------------------------
HtmlGenericControl div = new HtmlGenericControl();div.ID = "GridContainer";div.Controls.Add(this.GridControl);
2. Use javascript to open, send to print and close the Grid in a new window:
private void Print()
{
_gridControl.DisplayLayout.ReadOnly = ReadOnly.PrintingFriendly; string script = "<script language=javascript> " + " var prtContent = document.getElementById('" + div.ClientID + "'); " + " var WinPrint = window.open(); " +//'','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0'); " + " WinPrint.document.write(prtContent.innerHTML); " + " WinPrint.document.close(); " + " WinPrint.print(); " + " WinPrint.close(); " + "</script> "; Page.RegisterStartupScript("Script", script);
}
I found this useful.
Using custom rendering through HtmlTextWriter may indeed interfere with how the grid renders and prints. I have just read what Roger suggested and I believe his ideas are spot on - PDF is specifically used for printing, end-users are used to it and you have greater control there, so maybe you can implement print preview option in your site that essentially exports to PDF and end-users can print from there.
@Roger - thanks a lot for sharing this approach in forums. We will be working hard on updating the document export documentation for PDF/Excel/Word.
GokulKannanK,
I would strongly, stongly, and even more strongly recommend using the 'Infragistics.WebUI.UltraWebGrid.DocumentExport' and 'Infragistics.Documents.Report' libraries.
This 'Document Engine' seems to be in a rather early level as far as documentation - but, it is extremely powerful. Some Infragistics dude named Tim Hitchings pointed a customer to the online help. That forum post is at:
http://news.infragistics.com/forums/t/2867.aspx
The overall forum you would be interested in is at:
http://news.infragistics.com/forums/191.aspx
To show you how easy it is to simply print a grid with a report header here is a snippet:
// configure exporter
wgdx.DownloadName = "roster.pdf";
wgdx.TargetPaperOrientation = PageOrientation.Landscape;
wgdx.Export(wg);
There are examples pointed to in the documentation, and some extensive examples in the forum. For example, the above prints the grid without any report headers or footers. And, once you play with this tool you can see that you are not limited to printing one grid. You can print lots of grids on one report by creating report sections. And, you are not limited to grids - you can fairly easily create 'put-it-here' reports and use the Report.Publish() method.
Very extensive and very powerful and it will takes lots of time to get to the power
Enjoy.
Thanks Rumen,
I read the discussion and tried using readonly property but it did not help I even tried printerfriendly.
Is it because I am trying to render the grid using HtmlTextWriter.and even with this it only renders till the header.
any thoughts on this will be helpful
You can check out the discussion in the followin forum thread:
http://forums.infragistics.com/forums/p/3249/17797.aspx#17797
It provides a lot of information on printing grids and all related media/css problems.
One additional approach you may want to consider is first exporting the grid to Word / PDF and then provide the printing option from there (PDF in particular is very good for printing).