473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

print preview page question

I need to create a print preview page BUT my page I need to print has a grid
and in the grid I have 2 or 3 columns that have links I want to hide the
columns with the links on my print preview page so they don't print. Is that
possible to do and if so can someone point me somewhere or show my a code
snippet on how to do this?

Oct 13 '06 #1
9 4045
Hi,

You can do this by using different CSS rules for "screen" and "print" mode:

1) Add following stylesheet to your WebForm:

<style type="text/css" media="print">
.printOnly {
display: none;
}
</style>

<style type="text/css" media="screen">
.printOnly {
display: block;
}
</style>
2) Apply CSS class "printOnly" to your columns. Using GridView's BoundField
for example, we need to set 4 attributes:

<asp:BoundField ControlStyle-CssClass="printOnly"
HeaderStyle-CssClass="printOnly" ItemStyle-CssClass="printOnly"
FooterStyle-CssClass="printOnly" DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />

For more information about CSS and print, refer to:

http://www.pmob.co.uk/faqcss/tutorial03/index.htm
http://alistapart.com/articles/goingtoprint/

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 14 '06 #2
I can't get that working. I tried this before actually and the links in the
grid still showed in my print preview page

"Walter Wang [MSFT]" wrote:
Hi,

You can do this by using different CSS rules for "screen" and "print" mode:

1) Add following stylesheet to your WebForm:

<style type="text/css" media="print">
.printOnly {
display: none;
}
</style>

<style type="text/css" media="screen">
.printOnly {
display: block;
}
</style>
2) Apply CSS class "printOnly" to your columns. Using GridView's BoundField
for example, we need to set 4 attributes:

<asp:BoundField ControlStyle-CssClass="printOnly"
HeaderStyle-CssClass="printOnly" ItemStyle-CssClass="printOnly"
FooterStyle-CssClass="printOnly" DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />

For more information about CSS and print, refer to:

http://www.pmob.co.uk/faqcss/tutorial03/index.htm
http://alistapart.com/articles/goingtoprint/

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 18 '06 #3
i got the test code working but when i put it in my app its still showing the
links from my grid on my print preview page. I'm using a master page does
that make a difference? Here is what i have

<asp:GridView>
<asp:TemplateField InsertVisible="False" HeaderText="H"
ControlStyle-CssClass="printOnly">
<ItemTemplate><a href="www.msn.com">MSN</ItemTemplate>
</asp:GridView>
when I do print preview the link is still there, even when i go to my print
preview page its still there.

my print preview page:

function printpr(OLECMDID)
{
if (opener && !window.opener.closed)
{
document.writeln(opener.document.getElementById(tb l).outerHTML);
}
}
the grid appears here from the page calling it.
Is there an easier way to do this?
<asp:GridView
ID="GridView1" runat="server">
"Walter Wang [MSFT]" wrote:
Hi,

Which browser are you using? I just re-tested my test project using IE,
FireFox and Opera, all are working correctly by not showing the link column
in print preview mode.

I've attached my test web site here for your reference. Please tell me
whether or not this works for you. You might need to use Outlook Express to
download the attachment.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights
Oct 25 '06 #4
i got it working. though its still showing on my print preview page, the link
columns aren't printing. so I'm all set thanks

"igotyourdotnet" wrote:
i got the test code working but when i put it in my app its still showing the
links from my grid on my print preview page. I'm using a master page does
that make a difference? Here is what i have

<asp:GridView>
<asp:TemplateField InsertVisible="False" HeaderText="H"
ControlStyle-CssClass="printOnly">
<ItemTemplate><a href="www.msn.com">MSN</ItemTemplate>
</asp:GridView>
when I do print preview the link is still there, even when i go to my print
preview page its still there.

my print preview page:

function printpr(OLECMDID)
{
if (opener && !window.opener.closed)
{
document.writeln(opener.document.getElementById(tb l).outerHTML);
}
}
the grid appears here from the page calling it.
Is there an easier way to do this?
<asp:GridView
ID="GridView1" runat="server">
"Walter Wang [MSFT]" wrote:
Hi,

Which browser are you using? I just re-tested my test project using IE,
FireFox and Opera, all are working correctly by not showing the link column
in print preview mode.

I've attached my test web site here for your reference. Please tell me
whether or not this works for you. You might need to use Outlook Express to
download the attachment.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights
Oct 25 '06 #5
Hi,

Thank you very much for the update.

From your reply, it seems you're using your own "print preview page" using
some javascript? If this is the case, then the CSS rules will not work.
Previously I have thought "print preview" is using browser (such as IE) 's
print preview function.

However, it's still possible to hide some elements on demand, you just need
to apply different class to the client-side elements using javascript when
showing your print preview page.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 26 '06 #6
how could i do that with my own print preview page?
I would prefer not to how the links on my print preview page, as well, even
though they don't actually print, I would still like to hide them on the
preview page if possible.
"Walter Wang [MSFT]" wrote:
Hi,

Thank you very much for the update.

From your reply, it seems you're using your own "print preview page" using
some javascript? If this is the case, then the CSS rules will not work.
Previously I have thought "print preview" is using browser (such as IE) 's
print preview function.

However, it's still possible to hide some elements on demand, you just need
to apply different class to the client-side elements using javascript when
showing your print preview page.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 26 '06 #7
nevermind I just figured it out. thanks

I added the class to my output label on my print preview page.

"igotyourdotnet" wrote:
how could i do that with my own print preview page?
I would prefer not to how the links on my print preview page, as well, even
though they don't actually print, I would still like to hide them on the
preview page if possible.
"Walter Wang [MSFT]" wrote:
Hi,

Thank you very much for the update.

From your reply, it seems you're using your own "print preview page" using
some javascript? If this is the case, then the CSS rules will not work.
Previously I have thought "print preview" is using browser (such as IE) 's
print preview function.

However, it's still possible to hide some elements on demand, you just need
to apply different class to the client-side elements using javascript when
showing your print preview page.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 26 '06 #8
I do have one question though, is there a way to force the print preview page
to print in landscape?

"Walter Wang [MSFT]" wrote:
Hi,

Thank you very much for the update.

From your reply, it seems you're using your own "print preview page" using
some javascript? If this is the case, then the CSS rules will not work.
Previously I have thought "print preview" is using browser (such as IE) 's
print preview function.

However, it's still possible to hide some elements on demand, you just need
to apply different class to the client-side elements using javascript when
showing your print preview page.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 26 '06 #9
Based on your description, you're using following javascript to write out
html source as your own print preview page:

function printpr(OLECMDID)
{
if (opener && !window.opener.closed)
{
document.writeln(opener.document.getElementById(tb l).outerHTML);
}
}

I guess you don't have pagination in that way, right?

The difference of Portrait and Landscape is the page orientation when
viewing in preview mode. If you don't have pagination, then you need to
control the preview page width in different mode, I think you may use some
CSS rules to control the width.

By the way, can I ask why you need to implement the print preview while the
browser already has one? Also, the printing is still done by the browser,
right?

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Neo Geshel | last post by:
I'm helping on a web site, and it's got our knickers in a knot. We're using the same basic CSS files (with mods) and same headers as from our other sites, but the "print preview" won't work...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
4
by: zz | last post by:
Sorry for posting this here but unfortunatly I couldn't find any appropriate newsgroup for this and since I've been active here with .net question I figured you guys might be able to help. ...
0
by: ShaneO | last post by:
There have been similar questions raised in the past, however no answers seem to have been provided, so I thought I'd give it a go. Scenario 1: My Windows Forms app generates (say) 10 pages in a...
6
by: CSharpguy | last post by:
In my gridview I have 2 -3 template fields which are hyperlinks. I allow the user to print this grid. When the grid prints it also prints the links, how can I take the user to a print preview page...
7
by: itm | last post by:
I have a mail out to send to a group of owners with multiple accounts. I want to limit the number of accounts that print on the first page to 20. I want remaining accounts to print on a second...
16
by: kcddoorman | last post by:
Ok my database is working great. I've entered a whole bunch of orders into it and it is getting bigger. Say I have 3000 records and I want to print the form for the last 13. I go to print preview and...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
7
by: Fareast Adam | last post by:
I try to hide the print preview button that inside <div id="button"> when previewing the page. But the the problem happened the button is always hidden after i closing the preview page. Anyone have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.