Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > ASP.NET 4.5 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 14th, 2015, 03:11 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #2 (permalink)  
Old July 2nd, 2016, 01:35 AM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

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.

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

Last edited by mmorgan30; July 2nd, 2016 at 01:44 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09:25 AM
problem selecting listview item method Visual C++ 0 July 7th, 2006 05:06 PM
how to select an item from listview jthadathilm16 VB How-To 1 April 24th, 2006 12:33 PM
Selecting a ListView item bmains Pro VB.NET 2002/2003 0 January 22nd, 2005 11:19 PM



All times are GMT -4. The time now is 03:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.