473,696 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

print gridview but not print template fields

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
6 3466
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*******@disc ussions.microso ft.comwrote in message
news:E9******** *************** ***********@mic rosoft.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
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*******@disc ussions.microso ft.comwrote in message
news:E9******** *************** ***********@mic rosoft.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
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*******@disc ussions.microso ft.comwrote in message
news:8F******** *************** ***********@mic rosoft.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*******@disc ussions.microso ft.comwrote in message
news:E9******* *************** ************@mi crosoft.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

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=javasc ript>
function printpr(OLECMDI D)
{
if (opener && !window.opener. closed)
{
document.writel n(opener.docume nt.getElementBy Id('tbl').outer HTML);
}
}
</script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align=left>
<tr>
<td class="td_headi ng" width=100% align=left>
<asp:GridView ID="GridView1" runat="server" Width=100%>
</asp:GridView>
<script language="javas cript" type="text/javascript">
document.writel n(opener.docume nt.title);
</script>
</td>
</tr>
<tr>
<td class="td_gener al">
<script language="javas cript" 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*******@disc ussions.microso ft.comwrote in message
news:8F******** *************** ***********@mic rosoft.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*******@disc ussions.microso ft.comwrote in message
news:E9******** *************** ***********@mic rosoft.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

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=javasc ript>
function printpr(OLECMDI D)
{
if (opener && !window.opener. closed)
{
document.writel n(opener.docume nt.getElementBy Id('tbl').outer HTML);
}
}
</script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align=left>
<tr>
<td class="td_headi ng" width=100% align=left>
<asp:GridView ID="GridView1" runat="server" Width=100%>
</asp:GridView>
<script language="javas cript" type="text/javascript">
document.writel n(opener.docume nt.title);
</script>
</td>
</tr>
<tr>
<td class="td_gener al">
<script language="javas cript" 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*******@disc ussions.microso ft.comwrote in message
news:8F******** *************** ***********@mic rosoft.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*******@disc ussions.microso ft.comwrote in message
>news:E9******* *************** ************@mi crosoft.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:hidd en; display:none; }
}
@media Print {
.ScreenOnly { visibility:hidd en; display:none; }
}

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

Example:

<DIV class="PrintOnl y" >I will not be visible in the browser, but I'll
show up in printouts (and print Preview) </DIV>
<DIV class="ScreenOn ly" >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
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="#F FE0C0" BorderStyle="So lid" Width="100%" BorderWidth="1p x"
Font-Names="Verdana, Arial,Helvetica " AutoGenerateCol umns=False
CellPadding="1" >
<HeaderStyle BackColor="Maro on"
ForeColor="Lemo nChiffon" Font-Size="XX-Small" BorderColor="Ma roon"
BorderStyle="So lid" BorderWidth="1p x" />
<FooterStyle
BackColor="Tan" ></FooterStyle>
<Columns>
<asp:TemplateFi eld HeaderText="H" >
<ItemTemplate >
<a class="smalldar k" title="Details"
href="detail.as px?Id=<%# Eval("portfolio _id") %>"">Sale Details</a><br />
</ItemTemplate>
</asp:TemplateFie ld>
</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=javasc ript>
function printpr(OLECMDI D)
{
if (opener && !window.opener. closed)
{
document.writel n(opener.docume nt.getElementBy Id('tbl').outer HTML);
}
}
</script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align=left>
<tr>
<td class="td_headi ng" width=100% align=left>
<asp:GridView ID="GridView1" runat="server" Width=100%>
</asp:GridView>
<script language="javas cript" type="text/javascript">
document.writel n(opener.docume nt.title);
</script>
</td>
</tr>
<tr>
<td class="td_gener al">
<script language="javas cript" 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*******@disc ussions.microso ft.comwrote in message
news:8F******** *************** ***********@mic rosoft.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*******@disc ussions.microso ft.comwrote in message
news:E9******** *************** ***********@mic rosoft.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:hidd en; display:none; }
}
@media Print {
.ScreenOnly { visibility:hidd en; display:none; }
}

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

Example:

<DIV class="PrintOnl y" >I will not be visible in the browser, but I'll
show up in printouts (and print Preview) </DIV>
<DIV class="ScreenOn ly" >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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7975
by: steven | last post by:
Hello, I've created a Word-template for a letter. I've made some fields in the template (such as 'customer number', 'name', ...) as follows: insert field - DocVariabele with name 'customer number' and 'name'. Now I want to fill these fields from my application and print them: Dim myWord As New Word.Application myWord.Documents.Add("c:\template.dot")
4
9017
by: beton3000 | last post by:
Hello! I'm building a GridView using code to add template fields, because there is a random number of columns in result set from database. I'm using a class with ITemplate interface for defining columns. I am using a code which adds a checkbox for each column: public void InstantiateIn(System.Web.UI.Control container) { switch (templateType)
0
3773
by: agarwalsunitadhn | last post by:
hi.. How will i use print and print preview option. I have to print only a part of a page. for that i declare in a div and give that a id and then using java function to print that portion but my problem is that the page is directly printed and i am not getting the option of print preview. How will it possible?Please give me suggestion My code is as follows: code for aspx page <head> <script type="text/javascript">
1
1108
by: tswapnacm | last post by:
How to update and delete the data in gridview update template field
1
1339
by: agz29 | last post by:
How can i use the template fields of ultra web grid
1
5162
by: naasirsom | last post by:
Dear sir, I am using Gridview asp.net 2.0, I have a problem with Gridview Footer Template. I have put Button, Textbox and RequiredValidator in the Footer Template and Want to validate the textbox if it is empty and I used ValidationGroup . I have done all jobs and the page is working but the problem is the button is working the first time but the second time does not postback.
0
1016
by: Venkata Krishnam Raju | last post by:
Unable to find the Textbox in Gridview which Template controls created dynamically
1
4430
by: RobT | last post by:
*sigh* I can't get this to work. My program fills all the values into an Excel spreadsheet- no problems there. What I'd like to do is a print preview/print function. I can't seem to get my code right, all I get are blank pages in the print preview box. Dim oExcel As Object = CreateObject("Excel.Application") oExcel.Workbooks.Open("C:\DailyLogs\DailyLog.xlsx") PrintPreviewDialog1.Document =...
0
8656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8592
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9005
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4605
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2306
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.