Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > ASP.NET 4.5 General Discussion
ASP.NET 4.5 General Discussion For ASP.NET 4.5 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 14th, 2015, 02:11 PM
Registered User
Join Date: Mar 2015
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default Print ListView item template table with gridlines


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


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') ;");









ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());


Last edited by GeorgeLyzlie; September 15th, 2015 at 04:00 AM..
Old July 2nd, 2016, 12:35 AM
Friend of Wrox
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts

I am not sure I follow your question. if you are wanting your web application to have print functionality and base on the code you presented it seems as if you are printing an image of a gridview. this would already be built into a browser with the browser print button. no coding needed.

However if you are talking about the end-user being able to download a file version of your gridview that is printable, then you have to decide what format you want available. The easiest format of gridview to produce is a csv (comma separated value) file. When a user clicks your download link then you can do something like below to allow them to download a file.

Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=file.csv");
Response.Charset = "UTF-8";
Response.ContentType = "application/text";
where CsvUtil converts the GridView backing data ( an array of records) to a single csv string.

Last edited by mmorgan30; July 2nd, 2016 at 12:44 AM..

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get selected item from listview? try.test.abc C# 1 January 4th, 2007 02:34 AM
help coloring individual listview item instead al method Visual C++ 1 August 1st, 2006 08:25 AM
problem selecting listview item method Visual C++ 0 July 7th, 2006 04:06 PM
how to select an item from listview jthadathilm16 VB How-To 1 April 24th, 2006 11:33 AM
Selecting a ListView item bmains Pro VB.NET 2002/2003 0 January 22nd, 2005 11:19 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.