print preview page question

G

Guest

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?
 
W

Walter Wang [MSFT]

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 ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================

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

Guest

I can't get that working. I tried this before actually and the links in the
grid still showed in my print preview page
 
G

Guest

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(tbl).outerHTML);
}
}
the grid appears here from the page calling it.
Is there an easier way to do this?
<asp:GridView
ID="GridView1" runat="server">
 
G

Guest

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
G

Guest

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.
 
G

Guest

nevermind I just figured it out. thanks

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

Guest

I do have one question though, is there a way to force the print preview page
to print in landscape?
 
W

Walter Wang [MSFT]

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(tbl).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 ([email protected], 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top