how to take printout from the grid
-
i am having the grid which displays some table content, how to take printout of the whole datagrid content with the same format. Help me.
abul
-
i am having the grid which displays some table content, how to take printout of the whole datagrid content with the same format. Help me.
abul
make this function in your .aspx.cs file public static void PrintWebControl(Control ctrl) { PrintWebControl(ctrl, string.Empty); } public static void PrintWebControl(Control ctrl, string Script) { StringWriter stringWrite = new StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite); if (ctrl is WebControl) { Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w; } Page pg = new Page(); pg.EnableEventValidation = false; if (Script != string.Empty) { pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script); } HtmlForm frm = new HtmlForm(); pg.Controls.Add(frm); frm.Attributes.Add("runat", "server"); frm.Controls.Add(ctrl); pg.DesignerInitialize(); pg.RenderControl(htmlWrite); string strHTML = stringWrite.ToString(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Write(strHTML); HttpContext.Current.Response.Write("window.print();"); HttpContext.Current.Response.End(); } and then on button_click event write like following protected void printreport_Click(object sender, EventArgs e) { PrintWebControl(gvAnualReport); }