Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
| Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 22nd, 2004, 04:02 AM
Authorized User
 
Join Date: Dec 2004
Location: mumbai, maharastra, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to akhilvira
Default PRINTING DATA GRID IN ASP.NET

Hi
        I am using c# as the language to code. I have a datagrid in one of my webforms. I want to add print control to the webform so that the filled datagrid can be printed .
        Ne one having idea how to do that please do answers. Thnaks in advance to them

Akhil
  #2 (permalink)  
Old December 22nd, 2004, 04:24 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You could put your DataGrid inside an <iframe> and then use JavaScript to print just the contents of the frame.

Otherwise, I think you'll need to redirect to a page that displays just the datagrid, then print it, and then redirect again to the full page.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
  #3 (permalink)  
Old May 14th, 2005, 03:18 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you're dreaming ... I can find ways to print from WINDOWS forms but webforms doesn't seem to have a printdialog control needed to print the entire control. I've been able to email a copy of the datagrid using RENDERCONTROL (sp?) that document is an html file which can then be printed. That's as close as I've come. Good luck! Bob R.

  #4 (permalink)  
Old May 14th, 2005, 09:09 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You could also have some javascript that opens a new blank window, then uses document.write to write to that empty document the contents of only the datagrid. On the client side, you can access the HTML table that the grid renders by getting a client-side element reference using the value return from the server-side myGrid.ClientID property. This will get you the HTML table element from which you could get outerHtml or whatever that dom property is to get all of that element's HTML. This would then require no server-side roundtrip or extra pages.

-Peter
  #5 (permalink)  
Old November 28th, 2006, 05:41 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 You could also have some javascript that opens a new blank window, then uses document.write to write to that empty document the contents of only the datagrid. On the client side, you can access the HTML table that the grid renders by getting a client-side element reference using the value return from the server-side myGrid.ClientID property. This will get you the HTML table element from which you could get outerHtml or whatever that dom property is to get all of that element's HTML. This would then require no server-side roundtrip or extra pages.

-Peter
Peter, I'm really in need of doing this (print the content of datagrid on client side). I'm very new to .net so can you please provide me with some sample code to write this javascript? Urgent, please help. I really appreciate it.



  #6 (permalink)  
Old January 18th, 2007, 04:38 AM
Registered User
 
Join Date: Jan 2006
Location: Delhi, Delhi, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gyandeosingh Send a message via Yahoo to gyandeosingh
Default

1. Print a DataGrid Alone from an ASP.NET Web Page
URL : http://www.devx.com/tips/Tip/27626
Ever wanted to print a DataGrid alone from an ASP.NET Web page? Put an <asp:DataGrid> tag inside the tag does the trick. Here are the steps involved:
Enclose the <asp:datagrid></asp:datagrid> tag inside the <div></div> tag.
Write a JavaScript function which takes care of printing the content from <div> tag.
Here's an example:
<script language=javascript>
function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 prtContent.innerHTML=strOldOne;
}
</script>

<div id="divPrint">
<asp:datagrid>
.....
.....
.....
</asp:datagrid>
</div>
<asp:button ID="btnPrint" onClick="javascript:CallPrint('divPrint');" Runat=Server />
2. http://www.codeproject.com/useritems/Print_Grid.asp


Similar Threads
Thread Thread Starter Forum Replies Last Post
how data grid of vb.net add cell color Nuwang Forum and Wrox.com Feedback 0 September 10th, 2008 08:36 PM
Data Grid View Paging in VB.Net Prakash001 Visual Studio 2005 0 January 30th, 2008 07:44 AM
Grid View in ASP.NET 2.0 Using C# dhurjati_sen C# 2005 0 August 30th, 2007 11:44 PM
Refreshing a grid in asp.net 2.0 cpanson ASP.NET 2.0 Professional 3 March 5th, 2006 12:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.