Print ListView item template table with gridlines
Hi,
I have a ListView that has a table in its item template.
I would like to print it together with the table grid-lines.
I have tried several methods provided online and the grid-lines do not print at all.
Any help with sample code would be highly appreciated.
I tried this code from a certain forum.
protected void btnPrint_Click(object sender, EventArgs e)
{
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
ListView3.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());
ListView3.DataBind();
}
Last edited by GeorgeLyzlie; September 15th, 2015 at 05:00 AM.
|