System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid(); DataTable tempTbl = new DataTable(); //get my table columns here dg.DataSource = tempTbl; dg.AllowPaging = false; dg.AutoGenerateColumns = true; dg.DataBind(); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); dg.RenderControl(hw); string gridHTML = sw.ToString().Replace("\"", "'") .Replace(System.Environment.NewLine, ""); StringBuilder sb = new StringBuilder(); sb.Append("<script language='javascript' type='text/javascript'>"); sb.Append("window.onload = new function(){"); sb.Append("var printWin = window.open ('','','left =' + screen.width + ',top=' + screen.height + ',width=0,height=0,toolbar=0,scrollbars=0,status=0');"); sb.Append("printWin.document.write(\""); sb.Append(gridHTML); sb.Append("\");"); sb.Append("printWin.document.close();"); sb.Append("printWin.focus();"); sb.Append("printWin.print();"); sb.Append("printWin.close();};"); sb.Append("</script>"); System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JSCR", sb.ToString(), false);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)