By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,183 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,183 IT Pros & Developers. It's quick & easy.

print preview page question

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.