protected void PrintAllPages(object sender, EventArgs e) { GvLineBooking.AllowPaging = false; GvLineBooking.DataBind(); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); GvLineBooking.RenderControl(hw); string gridHTML = sw.ToString().Replace("\"", "'") .Replace(System.Environment.NewLine, ""); StringBuilder sb = new StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload = new function(){"); sb.Append("var printWin = window.open('', '', 'left=0"); sb.Append(",top=0,width=1000,height=600,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>"); ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString()); GvLineBooking.AllowPaging = true; GvLineBooking.DataBind(); }
protected void ExportToExcel(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=LinePlan.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages GvLineBooking.AllowPaging = false; this.BindGvorder(); GvLineBooking.HeaderRow.BackColor = Color.White; foreach (TableCell cell in GvLineBooking.HeaderRow.Cells) { cell.BackColor = GvLineBooking.HeaderStyle.BackColor; } foreach (GridViewRow row in GvLineBooking.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { if (row.RowIndex % 2 == 0) { cell.BackColor = GvLineBooking.AlternatingRowStyle.BackColor; } else { cell.BackColor = GvLineBooking.RowStyle.BackColor; } cell.CssClass = "textmode"; } } GvLineBooking.RenderControl(hw); //style to format numbers to string string style = @"<style> .textmode { } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } }