473,883 Members | 1,692 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 3484
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
7987
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
9029
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
3801
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
1116
by: tswapnacm | last post by:
How to update and delete the data in gridview update template field
1
1347
by: agz29 | last post by:
How can i use the template fields of ultra web grid
1
5196
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
1024
by: Venkata Krishnam Raju | last post by:
Unable to find the Textbox in Gridview which Template controls created dynamically
1
4443
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
9932
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
9778
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
11112
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10730
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
10833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10405
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
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
5980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3228
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.