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).
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).
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
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.