Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 June 17th, 2008, 05:26 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
Default Printing Contents of DetailsView - An Easy Way?

Ok, I have looked and looked and looked and have not found anything that seems to work correctly. My dilemma is this:

I have a gridview that displays a list of records, when a row is clicked a detailsview becomes visible with all of the columns for that particular record. I have added a imageButton to the Footer template of the detailsview in hopes to use this to print its contents.

The closest I have gotten is using a DIV tag - like so:

 '*** This is right before the <asp:DetailsView>, and the closing div right after obviously...
<div id="DetailsDiv" runat="server" visible="true">

<FooterTemplate>
                <asp:ImageButton ID="btn_Print" runat="server" ImageAlign="Left"
                    ImageUrl="~/images/icon_print.gif"
                    onclientclick="javascript:PrintDiv('DetailsDiv')" />
</FooterTemplate>

And my javascript function:

<script type="text/javascript">
<!--
function PrintDiv(elementId)
{
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=5=,top=5,width=500,height=700');

 printWindow.document.write(printContent.innerHTML) ;
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}
// -->
</script>

The only thing this does is open a blank window the size I want it to. There is no data in the window, nor does the print dialog come up.

Anyone know of a either a better way to do this - OR am I missing something in this that can just be fixed to make it work?




The Following User Says Thank You to kevorkian For This Useful Post:
 
Old June 17th, 2008, 05:55 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

It's a bit hacky, but...

Have you considered turning *OFF* the display for all elements on the page *EXCEPT* that <DIV> when you want to print it??

That is, if the page is laid out via

<BODY>
<DIV id=maincontent>
...
</DIV>
<DIV id=details>
...
</DIV>
<DIV id=footerMaybe>
...
</DIV>
</BODY>

then if you applied .style.display='none'; to the maincontent and footerMaybe divs...

Hmmm???
 
Old June 17th, 2008, 05:59 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
Default

I actually have seen that as a way of doing it - I just have no yet tried it. I have so much on the page that I wanted to avoid it if at all possible.

From what I have found and heard back though - that may be my only way...

 
Old June 9th, 2010, 12:24 PM
ddd
Guest
 
Posts: n/a
Default Printing a content Of a DIV

from this link you can get the answer

http://forums.asp.net/t/1556818.aspx

1- add this script to the content of your page

<script type="text/javascript"> function doPrint() { var prtContent = document.getElementById('<%= DetailsDiv.ClientID %>'); prtContent.border = 0; //set no border here var WinPrint = window.open('', '', 'left=100,top=100,width=1000,height=1000,toolbar=0 ,scrollbars=1,status=0,resizable=1'); WinPrint.document.write(prtContent.outerHTML); WinPrint.document.close(); WinPrint.focus(); WinPrint.print(); WinPrint.close(); } </script>
<script type="text/javascript">

function doPrint() {

var prtContent = document.getElementById('<%= DetailsDiv.ClientID %>');

prtContent.border = 0; //set no border here

var WinPrint = window.open('', '', 'left=100,top=100,width=1000,height=1000,toolbar=0 ,scrollbars=1,status=0,resizable=1');

WinPrint.document.write(prtContent.outerHTML);

WinPrint.document.close();

WinPrint.focus();

WinPrint.print();

WinPrint.close();

}

</script>

2- add image button or link button and add this code to

<asp:ImageButton ID="BtnPrint" OnClientClick="doPrint()" ImageUrl="~/GraduateStudiesReg/imagefs (1).JPG" runat="server" />

Mahmoud Moustafa




Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing the contents of a Gridview akhilhp ASP.NET 2.0 Professional 0 January 10th, 2007 02:01 AM
Printing the contents of an RTFTextBox John Douglas C# 0 October 15th, 2006 04:04 PM
Easy One ru1 Access 2 September 15th, 2006 10:36 PM
capturing printing settings when printing reports nikolaosk Access VBA 0 February 8th, 2005 04:14 AM
This should be easy benibell Javascript 1 June 22nd, 2004 05:50 PM





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