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

print gridview but not print template fields

P: n/a
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 and not show the templated
fields, (hyperlinks) and also not print those fields?

Sep 11 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Two client-side events onbeforeprint and onafterprint are designed to change
the page appearance before printing and to restore it after printing. You
can find the links and hide/show them in these events with javascript.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:E9**********************************@microsof t.com...
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 and not show the templated
fields, (hyperlinks) and also not print those fields?

Sep 11 '06 #2

P: n/a
do you have an example or now of an example somewhere?

"Eliyahu Goldin" wrote:
Two client-side events onbeforeprint and onafterprint are designed to change
the page appearance before printing and to restore it after printing. You
can find the links and hide/show them in these events with javascript.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:E9**********************************@microsof t.com...
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 and not show the templated
fields, (hyperlinks) and also not print those fields?


Sep 11 '06 #3

P: n/a
What would you like to see in the example? How to use the events or how to
find the links?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
do you have an example or now of an example somewhere?

"Eliyahu Goldin" wrote:
>Two client-side events onbeforeprint and onafterprint are designed to
change
the page appearance before printing and to restore it after printing. You
can find the links and hide/show them in these events with javascript.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:E9**********************************@microso ft.com...
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 and not show the templated
fields, (hyperlinks) and also not print those fields?



Sep 11 '06 #4

P: n/a

here's the problem i'm running into.
I'm using a master page and the gridview is in the content section. The grid
view has 2 or 3 columns (based on the page) that are links using a template
field and <a href=for the links. When the user clicks my print button, I
take them to a print preview page which is like a snap shot of the page but
without the master page surrounding it.

Here is my code I'm using. (if there is another easier way, I'm all for it)
this is my print preview page only:
<script language=javascript>
function printpr(OLECMDID)
{
if (opener && !window.opener.closed)
{
document.writeln(opener.document.getElementById('t bl').outerHTML);
}
}
</script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align=left>
<tr>
<td class="td_heading" width=100% align=left>
<asp:GridView ID="GridView1" runat="server" Width=100%>
</asp:GridView>
<script language="javascript" type="text/javascript">
document.writeln(opener.document.title);
</script>
</td>
</tr>
<tr>
<td class="td_general">
<script language="javascript" type="text/javascript">
<!--//
printpr(7);
//-->
</script>
</td>
</tr>
</table>
so what this is doing is taken the control (gridview in this case) from the
main page and showing it on the print page just as it is on the page. So I
need to remove the template field (link) on or before they ever show in the
print preview page
"Eliyahu Goldin" wrote:
What would you like to see in the example? How to use the events or how to
find the links?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
do you have an example or now of an example somewhere?

"Eliyahu Goldin" wrote:
Two client-side events onbeforeprint and onafterprint are designed to
change
the page appearance before printing and to restore it after printing. You
can find the links and hide/show them in these events with javascript.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:E9**********************************@microsof t.com...
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 and not show the templated
fields, (hyperlinks) and also not print those fields?



Sep 11 '06 #5

P: n/a

CSharpguy wrote:
here's the problem i'm running into.
I'm using a master page and the gridview is in the content section. The grid
view has 2 or 3 columns (based on the page) that are links using a template
field and <a href=for the links. When the user clicks my print button, I
take them to a print preview page which is like a snap shot of the page but
without the master page surrounding it.

Here is my code I'm using. (if there is another easier way, I'm all for it)
this is my print preview page only:
<script language=javascript>
function printpr(OLECMDID)
{
if (opener && !window.opener.closed)
{
document.writeln(opener.document.getElementById('t bl').outerHTML);
}
}
</script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align=left>
<tr>
<td class="td_heading" width=100% align=left>
<asp:GridView ID="GridView1" runat="server" Width=100%>
</asp:GridView>
<script language="javascript" type="text/javascript">
document.writeln(opener.document.title);
</script>
</td>
</tr>
<tr>
<td class="td_general">
<script language="javascript" type="text/javascript">
<!--//
printpr(7);
//-->
</script>
</td>
</tr>
</table>
so what this is doing is taken the control (gridview in this case) from the
main page and showing it on the print page just as it is on the page. So I
need to remove the template field (link) on or before they ever show in the
print preview page
"Eliyahu Goldin" wrote:
What would you like to see in the example? How to use the events or howto
find the links?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
do you have an example or now of an example somewhere?
>
"Eliyahu Goldin" wrote:
>
>Two client-side events onbeforeprint and onafterprint are designed to
>change
>the page appearance before printing and to restore it after printing.. You
>can find the links and hide/show them in these events with javascript.
>>
>--
>Eliyahu Goldin,
>Software Developer & Consultant
>Microsoft MVP [ASP.NET]
>>
>>
>"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
>news:E9**********************************@microso ft.com...
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 and not show the templated
fields, (hyperlinks) and also not print those fields?
>
If your target browsers are advanced enough, a CSS solution may be
simpler
I typically use

@media Screen {
.PrintOnly { visibility:hidden; display:none; }
}
@media Print {
.ScreenOnly { visibility:hidden; display:none; }
}

set the css classes on the appropriate controls, and voilą!

Example:

<DIV class="PrintOnly" >I will not be visible in the browser, but I'll
show up in printouts (and print Preview) </DIV>
<DIV class="ScreenOnly" >I'm in the browser, but not in printouts (or
print Preview) </DIV>
Who needs pesky javascript :)

Hope this helps -
-- a --

Sep 11 '06 #6

P: n/a
that won't work in my scenario. Not with the links embedded into the grid as
such:

<asp:GridView ID="grdSales" runat="server" Font-Size="XX-Small"
BorderColor="#FFE0C0" BorderStyle="Solid" Width="100%" BorderWidth="1px"
Font-Names="Verdana,Arial,Helvetica" AutoGenerateColumns=False
CellPadding="1">
<HeaderStyle BackColor="Maroon"
ForeColor="LemonChiffon" Font-Size="XX-Small" BorderColor="Maroon"
BorderStyle="Solid" BorderWidth="1px" />
<FooterStyle
BackColor="Tan"></FooterStyle>
<Columns>
<asp:TemplateField HeaderText="H" >
<ItemTemplate>
<a class="smalldark" title="Details"
href="detail.aspx?Id=<%# Eval("portfolio_id") %>"">Sale Details</a><br />
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>

"addup" wrote:
>
CSharpguy wrote:
here's the problem i'm running into.
I'm using a master page and the gridview is in the content section. The grid
view has 2 or 3 columns (based on the page) that are links using a template
field and <a href=for the links. When the user clicks my print button, I
take them to a print preview page which is like a snap shot of the page but
without the master page surrounding it.

Here is my code I'm using. (if there is another easier way, I'm all for it)
this is my print preview page only:
<script language=javascript>
function printpr(OLECMDID)
{
if (opener && !window.opener.closed)
{
document.writeln(opener.document.getElementById('t bl').outerHTML);
}
}
</script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align=left>
<tr>
<td class="td_heading" width=100% align=left>
<asp:GridView ID="GridView1" runat="server" Width=100%>
</asp:GridView>
<script language="javascript" type="text/javascript">
document.writeln(opener.document.title);
</script>
</td>
</tr>
<tr>
<td class="td_general">
<script language="javascript" type="text/javascript">
<!--//
printpr(7);
//-->
</script>
</td>
</tr>
</table>
so what this is doing is taken the control (gridview in this case) from the
main page and showing it on the print page just as it is on the page. So I
need to remove the template field (link) on or before they ever show in the
print preview page
"Eliyahu Goldin" wrote:
What would you like to see in the example? How to use the events or how to
find the links?
>
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
>
>
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
do you have an example or now of an example somewhere?

"Eliyahu Goldin" wrote:

Two client-side events onbeforeprint and onafterprint are designed to
change
the page appearance before printing and to restore it after printing.. You
can find the links and hide/show them in these events with javascript.
>
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
>
>
"CSharpguy" <CS*******@discussions.microsoft.comwrote in message
news:E9**********************************@microsof t.com...
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 and not show the templated
fields, (hyperlinks) and also not print those fields?

If your target browsers are advanced enough, a CSS solution may be
simpler
I typically use

@media Screen {
.PrintOnly { visibility:hidden; display:none; }
}
@media Print {
.ScreenOnly { visibility:hidden; display:none; }
}

set the css classes on the appropriate controls, and voilĆ*!

Example:

<DIV class="PrintOnly" >I will not be visible in the browser, but I'll
show up in printouts (and print Preview) </DIV>
<DIV class="ScreenOnly" >I'm in the browser, but not in printouts (or
print Preview) </DIV>
Who needs pesky javascript :)

Hope this helps -
-- a --

Sep 11 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.